aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/math
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-13 22:11:06 +0200
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-13 22:11:06 +0200
commitdc4d89e2b91012334855bbbf184df32aa5d6d982 (patch)
tree1e3062deee871c193a7debcf061a3e05ef02fbc0 /test/monniaux/math
parentc819b4be371dd44704956a80532fdcf8f5e9b833 (diff)
downloadcompcert-kvx-dc4d89e2b91012334855bbbf184df32aa5d6d982.tar.gz
compcert-kvx-dc4d89e2b91012334855bbbf184df32aa5d6d982.zip
some more examples
Diffstat (limited to 'test/monniaux/math')
-rw-r--r--test/monniaux/math/exceptions.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/test/monniaux/math/exceptions.c b/test/monniaux/math/exceptions.c
index d4a6a26b..05423e62 100644
--- a/test/monniaux/math/exceptions.c
+++ b/test/monniaux/math/exceptions.c
@@ -2,8 +2,9 @@
#include <fenv.h>
#include <float.h>
-#ifdef __K1C__
-#include <mppa_bare_runtime/k1c/registers.h>
+#pragma STDC FENV_ACCESS ON
+
+#ifdef __GNUC__
int fetestexcept(int excepts) {
int mask = (K1_SFR_CS_IO_MASK | K1_SFR_CS_DZ_MASK | K1_SFR_CS_OV_MASK | K1_SFR_CS_UN_MASK | K1_SFR_CS_IN_MASK) & excepts;
unsigned long long cs = __builtin_k1_get(K1_SFR_CS);
@@ -17,8 +18,6 @@ int feclearexcept(int excepts) {
}
#endif
-#pragma STDC FENV_ACCESS ON
-
double add(double x, double y) {
return x+y;
}
@@ -27,15 +26,51 @@ double mul(double x, double y) {
return x*y;
}
+float double2float(double x) {
+ return x;
+}
+
+float uint2float(unsigned x) {
+ return x;
+}
+
+double ulong2double(unsigned long x) {
+ return x;
+}
+
+unsigned double2uint(double x) {
+ return x;
+}
+
int main() {
printf("%x\n", fetestexcept(FE_ALL_EXCEPT));
+
double v1 = add(3.0, 0.1);
printf("%x\n", fetestexcept(FE_ALL_EXCEPT));
feclearexcept(FE_INEXACT);
+
printf("%x\n", fetestexcept(FE_ALL_EXCEPT));
double v2 = mul(DBL_MAX, DBL_MAX);
printf("%g %x\n", v2, fetestexcept(FE_ALL_EXCEPT));
feclearexcept(FE_ALL_EXCEPT);
+
double v3 = mul(DBL_MIN, DBL_MIN);
printf("%g %x\n", v3, fetestexcept(FE_ALL_EXCEPT));
+ feclearexcept(FE_ALL_EXCEPT);
+
+ double v4 = double2float(DBL_MAX);
+ printf("%g %x\n", v4, fetestexcept(FE_ALL_EXCEPT));
+ feclearexcept(FE_ALL_EXCEPT);
+
+ float v5 = uint2float(0xC07FDFFFU);
+ printf("%g %x\n", v5, fetestexcept(FE_ALL_EXCEPT)); // BUG 0 should have INEXACT
+ feclearexcept(FE_ALL_EXCEPT);
+
+ double v6 = ulong2double(0x11217763AFF77C7CUL);
+ printf("%g %x\n", v6, fetestexcept(FE_ALL_EXCEPT)); // BUG 0 should have INEXACT
+ feclearexcept(FE_ALL_EXCEPT);
+
+ unsigned v7 = double2uint(-0.25); // softfloat says "0 and inexact" but here we have "0 and overflow" (due to negative input for unsigned?)
+ printf("%u %x\n", v7, fetestexcept(FE_ALL_EXCEPT));
+ feclearexcept(FE_ALL_EXCEPT);
}