summaryrefslogtreecommitdiff
path: root/support/regression/tests/bitinttofloat.c.in
diff options
context:
space:
mode:
Diffstat (limited to 'support/regression/tests/bitinttofloat.c.in')
-rw-r--r--support/regression/tests/bitinttofloat.c.in44
1 files changed, 44 insertions, 0 deletions
diff --git a/support/regression/tests/bitinttofloat.c.in b/support/regression/tests/bitinttofloat.c.in
new file mode 100644
index 000000000..1645c5b3f
--- /dev/null
+++ b/support/regression/tests/bitinttofloat.c.in
@@ -0,0 +1,44 @@
+/** casts between bit-precise integers and float
+
+ width: 2, 4, 6, 7, 8, 9, 15, 16, 17, 24, 32, 33, 40, 48, 63, 64, 65
+ sign: unsigned, signed
+*/
+
+#include <testfwk.h>
+
+#include <float.h>
+
+// clang 11 supports bit-precise types, but deviates a bit from C23.
+#if __clang_major__ == 11
+#define __SDCC_BITINT_MAXWIDTH 128
+#define _BitInt _ExtInt
+#endif
+
+#if __SDCC_BITINT_MAXWIDTH >= {width} // TODO: When we can regression-test in --std-c23 mode, use the standard macro from limits.h instead!
+
+typedef {sign} _BitInt({width}) bitinttype;
+
+float to_float(bitinttype b)
+{
+ return(b);
+}
+#endif
+
+void testCast (void)
+{
+#if __SDCC_BITINT_MAXWIDTH >= {width} // TODO: When we can regression-test in --std-c23 mode, use the standard macro from limits.h instead!
+ bitinttype b;
+
+ b = 1;
+ ASSERT (to_float (b) == (float)b);
+ b = 23;
+ ASSERT (to_float (b) == (float)b);
+#if {width} <= FLT_MANT_DIG
+ b = -1;
+ ASSERT (to_float (b) == (float)b);
+ b = -23;
+ ASSERT (to_float (b) == (float)b);
+#endif
+#endif
+}
+