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