summaryrefslogtreecommitdiffstats
path: root/progs/gallium/unit/u_half_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'progs/gallium/unit/u_half_test.c')
-rw-r--r--progs/gallium/unit/u_half_test.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/progs/gallium/unit/u_half_test.c b/progs/gallium/unit/u_half_test.c
new file mode 100644
index 00000000000..0486f731acd
--- /dev/null
+++ b/progs/gallium/unit/u_half_test.c
@@ -0,0 +1,31 @@
+#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;
+ f.ui = util_half_to_floatui(h);
+ half 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;
+}