MCPcopy Create free account
hub / github.com/NVIDIA-RTX/Donut / test_known_float16

Function test_known_float16

tests/src/engine/test_float.cpp:65–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65bool test_known_float16()
66{
67 // See https://en.wikipedia.org/wiki/Half-precision_floating-point_format#Half_precision_examples
68 const float inv1024 = 1.f / 1024.f;
69 const float smallestNormal = powf(2.f, -14.f);
70
71 using f32lim = std::numeric_limits<float>;
72 using f16lim = std::numeric_limits<float16_t>;
73
74 bool pass = true;
75 pass &= check_known_float16(0.f, 0);
76 pass &= check_known_float16(smallestNormal * inv1024 * 0.5f, 0); // underflow
77 pass &= check_known_float16(smallestNormal * inv1024, f16lim::denorm_min().bits);
78 pass &= check_known_float16(smallestNormal * inv1024 * 1023.f, 0x03ff);
79 pass &= check_known_float16(1.f / 3.f, 0x3555);
80 pass &= check_known_float16(0.5f * (1.f + 1023.f / 1024.f), 0x3bff);
81 pass &= check_known_float16(1.f, 0x3c00);
82 pass &= check_known_float16(1.f + inv1024, 0x3c01);
83 pass &= check_known_float16(65504.f, f16lim::max().bits); // largest finite number
84 pass &= check_known_float16(f32lim::infinity(), f16lim::infinity().bits);
85 pass &= check_known_float16(-f32lim::infinity(), 0xfc00);
86 pass &= check_known_float16(f32lim::quiet_NaN(), f16lim::quiet_NaN().bits);
87 pass &= check_known_float16(f32lim::signaling_NaN(), f16lim::quiet_NaN().bits); // no signaling NaN here
88 pass &= check_known_float16(65519.f, f16lim::max().bits); // not quite overflow to Inf
89 pass &= check_known_float16(65520.f, f16lim::infinity().bits); // overflow to Inf
90 pass &= check_known_float16(1000000.f, f16lim::infinity().bits); // overflow to Inf
91 return pass;
92}
93
94bool test_float16_vectors()
95{

Callers 1

mainFunction · 0.85

Calls 2

check_known_float16Function · 0.85
maxFunction · 0.50

Tested by

no test coverage detected