1 #include <stdlib.h> 2 #include <stdio.h> 3 #include <float.h> 4 5 #include "util/u_math.h" 6 #include "util/u_half.h" 7 8 int main(int argc,char ** argv)9main(int argc, char **argv) 10 { 11 unsigned i; 12 unsigned roundtrip_fails = 0; 13 14 for(i = 0; i < 1 << 16; ++i) 15 { 16 uint16_t h = (uint16_t) i; 17 union fi f; 18 uint16_t rh; 19 20 f.f = util_half_to_float(h); 21 rh = util_float_to_half(f.f); 22 23 if (h != rh && !(util_is_half_nan(h) && util_is_half_nan(rh))) { 24 printf("Roundtrip failed: %x -> %x = %f -> %x\n", h, f.ui, f.f, rh); 25 ++roundtrip_fails; 26 } 27 } 28 29 if(roundtrip_fails) 30 printf("Failure! %u/65536 half floats failed a conversion to float and back.\n", roundtrip_fails); 31 else 32 printf("Success!\n"); 33 34 return 0; 35 } 36