summaryrefslogtreecommitdiff
path: root/test/float_ops_precise.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-18 11:32:15 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-18 11:32:15 -0800
commitcb41c9a8b11970a01e3f2f1eb2d8d38e29e7489b (patch)
treebfd1ac870bd98e0e0b9af0d19d93baf8c9ac6eb8 /test/float_ops_precise.cpp
parent25804b0a505beda9efb0b0fa2e8a1bde7e401042 (diff)
downloadbinaryen-cb41c9a8b11970a01e3f2f1eb2d8d38e29e7489b.tar.gz
binaryen-cb41c9a8b11970a01e3f2f1eb2d8d38e29e7489b.tar.bz2
binaryen-cb41c9a8b11970a01e3f2f1eb2d8d38e29e7489b.zip
add precise float tests
Diffstat (limited to 'test/float_ops_precise.cpp')
-rw-r--r--test/float_ops_precise.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/float_ops_precise.cpp b/test/float_ops_precise.cpp
new file mode 100644
index 000000000..ddd8bcae6
--- /dev/null
+++ b/test/float_ops_precise.cpp
@@ -0,0 +1,45 @@
+#include <cmath>
+#include <algorithm>
+#include <emscripten.h>
+
+extern "C" {
+
+// unary
+double EMSCRIPTEN_KEEPALIVE dneg(double x) { return -x; }
+double EMSCRIPTEN_KEEPALIVE dfloor(double x) { return floor(x); }
+
+// binary
+double EMSCRIPTEN_KEEPALIVE dadd(double x, double y) { return x + y; }
+double EMSCRIPTEN_KEEPALIVE dsub(double x, double y) { return x - y; }
+double EMSCRIPTEN_KEEPALIVE dmul(double x, double y) { return x * y; }
+double EMSCRIPTEN_KEEPALIVE ddiv(double x, double y) { return x / y; }
+double EMSCRIPTEN_KEEPALIVE dcopysign(double x, double y) { return std::copysign(x, y); }
+double EMSCRIPTEN_KEEPALIVE dmin(double x, double y) { return std::min(x, y); }
+double EMSCRIPTEN_KEEPALIVE dmax(double x, double y) { return std::max(x, y); }
+
+// comparisons
+int EMSCRIPTEN_KEEPALIVE deq(double x, double y) { return x == y; }
+int EMSCRIPTEN_KEEPALIVE dne(double x, double y) { return x != y; }
+int EMSCRIPTEN_KEEPALIVE dlt(double x, double y) { return x < y; }
+int EMSCRIPTEN_KEEPALIVE dle(double x, double y) { return x <= y; }
+int EMSCRIPTEN_KEEPALIVE dgt(double x, double y) { return x > y; }
+int EMSCRIPTEN_KEEPALIVE dge(double x, double y) { return x >= y; }
+
+double EMSCRIPTEN_KEEPALIVE int_to_double(int x) {
+ double d = x;
+ return d + 1.23;
+}
+
+double EMSCRIPTEN_KEEPALIVE uint_to_double(unsigned x) {
+ double d = x;
+ return d + 1.23;
+}
+
+int EMSCRIPTEN_KEEPALIVE double_to_int(double d) {
+ d += 1.23;
+ int x = d;
+ return x;
+}
+
+}
+