| 288 | } |
| 289 | |
| 290 | bool test_float8e4m3() |
| 291 | { |
| 292 | float8e4m3_t f8i; |
| 293 | float8e4m3_t f8o; |
| 294 | float f32; |
| 295 | uint32_t errorCount = 0; |
| 296 | for (int i = 0; i < 256; ++i) |
| 297 | { |
| 298 | f8i.bits = i; |
| 299 | f32 = Float8E4M3ToFloat32(f8i); |
| 300 | f8o = Float32ToFloat8E4M3(f32); |
| 301 | |
| 302 | bool pass; |
| 303 | CHECK(!isinf(f8i)); // E4M3 doesn't support INF |
| 304 | if (isnan(f8i)) |
| 305 | pass = std::isnan(f32) == isnan(f8o); |
| 306 | else |
| 307 | pass = f8o.bits == f8i.bits && std::isfinite(f32) == isfinite(f8o); |
| 308 | |
| 309 | if (!pass) |
| 310 | { |
| 311 | ++errorCount; |
| 312 | if (errorCount < MAX_ERRORS) |
| 313 | { |
| 314 | fprintf(stderr, "E4M3 mismatch: expected 0x%02x, got 0x%02x, float value %f\n", |
| 315 | f8i.bits, f8o.bits, f32); |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | if (errorCount >= MAX_ERRORS) |
| 321 | { |
| 322 | fprintf(stderr, "... %u more error(s) ...\n", errorCount - MAX_ERRORS); |
| 323 | } |
| 324 | |
| 325 | return errorCount == 0; |
| 326 | } |
| 327 | |
| 328 | bool check_known_float8e5m2(float in, uint8_t out) |
| 329 | { |
no test coverage detected