From: Nadav Har'El <n...@scylladb.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master
math: add nearbyint() and friends
nearbyint() is just like rint(), with slightly different handling of
"inexact" exceptions. Just use the Musl implementation (we need to
ignore warnings on unsupported #pragmas in those files).
Fixes #851.
Signed-off-by: Nadav Har'El <n...@scylladb.com>
Message-Id: <20170206085535.24209-1-...@scylladb.com>
---
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -1220,9 +1220,12 @@ musl += math/modfl.o
musl += math/nan.o
musl += math/nanf.o
musl += math/nanl.o
-#musl += math/nearbyint.o
-#musl += math/nearbyintf.o
-#musl += math/nearbyintl.o
+musl += math/nearbyint.o
+$(out)/musl/src/math/nearbyint.o: CFLAGS += -Wno-unknown-pragmas
+musl += math/nearbyintf.o
+$(out)/musl/src/math/nearbyintf.o: CFLAGS += -Wno-unknown-pragmas
+musl += math/nearbyintl.o
+$(out)/musl/src/math/nearbyintl.o: CFLAGS += -Wno-unknown-pragmas
musl += math/nextafter.o
musl += math/nextafterf.o
musl += math/nextafterl.o
diff --git a/modules/tests/Makefile b/modules/tests/Makefile
--- a/modules/tests/Makefile
+++ b/modules/tests/Makefile
@@ -85,7 +85,7 @@ tests := tst-pthread.so misc-ramdisk.so tst-vblk.so
tst-bsd-evh.so \
payload-merge-env.so misc-execve.so misc-execve-payload.so misc-mutex2.so
\
tst-pthread-setcancelstate.so tst-syscall.so tst-pin.so tst-run.so \
tst-ifaddrs.so tst-pthread-affinity-inherit.so tst-sem-timed-wait.so \
- tst-ttyname.so tst-pthread-barrier.so tst-feexcept.so
+ tst-ttyname.so tst-pthread-barrier.so tst-feexcept.so tst-math.so
# libstatic-thread-variable.so tst-static-thread-variable.so \
diff --git a/tests/tst-math.cc b/tests/tst-math.cc
--- a/tests/tst-math.cc
+++ b/tests/tst-math.cc
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 ScyllaDB, Ltd.
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+// This test works on both Linux and OSv.
+// To compile on Linux, use: c++ -std=c++11 tests/tst-math.cc
+
+#include <math.h>
+
+#include <iostream>
+
+static int tests = 0, fails = 0;
+
+#define expect(actual, expected) do_expect(actual, expected, #actual,
#expected, __FILE__, __LINE__)
+template<typename T>
+bool do_expect(T actual, T expected, const char *actuals, const char
*expecteds, const char *file, int line)
+{
+ ++tests;
+ if (actual != expected) {
+ fails++;
+ std::cout << "FAIL: " << file << ":" << line << ": For " <<
actuals <<
+ ", expected " << expecteds << ", saw " << actual << ".\n";
+ return false;
+ }
+ return true;
+}
+
+#define expect_errno(call, experrno) ( \
+ do_expect(call, -1, #call, "-1", __FILE__, __LINE__) && \
+ do_expect(errno, experrno, #call " errno", #experrno, __FILE__,
__LINE__) )
+
+int main(int argc, char **argv)
+{
+ // Test nearbyint()
+ expect(nearbyint(1.3), 1.0);
+ expect(nearbyint(1.7), 2.0);
+
+ std::cout << "SUMMARY: " << tests << " tests, " << fails << "
failures\n";
+ return fails == 0 ? 0 : 1;
+}
--
You received this message because you are subscribed to the Google Groups "OSv
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.