[libcxx] r349387 - Fix FP comparisons when SSE isn't available
Eric Fiselier
eric at efcs.ca
Mon Dec 17 12:17:43 PST 2018
Author: ericwf
Date: Mon Dec 17 12:17:43 2018
New Revision: 349387
URL: http://llvm.org/viewvc/llvm-project?rev=349387&view=rev
Log:
Fix FP comparisons when SSE isn't available
Added:
libcxx/trunk/test/support/truncate_fp.h
Modified:
libcxx/trunk/test/std/depr/depr.c.headers/math_h.pass.cpp
libcxx/trunk/test/std/numerics/c.math/cmath.pass.cpp
libcxx/trunk/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp
libcxx/trunk/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp
Modified: libcxx/trunk/test/std/depr/depr.c.headers/math_h.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/depr.c.headers/math_h.pass.cpp?rev=349387&r1=349386&r2=349387&view=diff
==============================================================================
--- libcxx/trunk/test/std/depr/depr.c.headers/math_h.pass.cpp (original)
+++ libcxx/trunk/test/std/depr/depr.c.headers/math_h.pass.cpp Mon Dec 17 12:17:43 2018
@@ -14,6 +14,7 @@
#include <cassert>
#include "hexfloat.h"
+#include "truncate_fp.h"
// convertible to int/float/double/etc
template <class T, int N=0>
@@ -807,23 +808,31 @@ void test_atanh()
assert(atanh(0) == 0);
}
-void test_cbrt()
-{
- static_assert((std::is_same<decltype(cbrt((float)0)), float>::value), "");
- static_assert((std::is_same<decltype(cbrt((bool)0)), double>::value), "");
- static_assert((std::is_same<decltype(cbrt((unsigned short)0)), double>::value), "");
- static_assert((std::is_same<decltype(cbrt((int)0)), double>::value), "");
- static_assert((std::is_same<decltype(cbrt((unsigned int)0)), double>::value), "");
- static_assert((std::is_same<decltype(cbrt((long)0)), double>::value), "");
- static_assert((std::is_same<decltype(cbrt((unsigned long)0)), double>::value), "");
- static_assert((std::is_same<decltype(cbrt((long long)0)), double>::value), "");
- static_assert((std::is_same<decltype(cbrt((unsigned long long)0)), double>::value), "");
- static_assert((std::is_same<decltype(cbrt((double)0)), double>::value), "");
- static_assert((std::is_same<decltype(cbrt((long double)0)), long double>::value), "");
+void test_cbrt() {
+ static_assert((std::is_same<decltype(cbrt((float) 0)), float>::value), "");
+ static_assert((std::is_same<decltype(cbrt((bool) 0)), double>::value), "");
+ static_assert((std::is_same<decltype(cbrt((unsigned short) 0)),
+ double>::value), "");
+ static_assert((std::is_same<decltype(cbrt((int) 0)), double>::value), "");
+ static_assert((std::is_same<decltype(cbrt((unsigned int) 0)),
+ double>::value), "");
+ static_assert((std::is_same<decltype(cbrt((long) 0)), double>::value), "");
+ static_assert((std::is_same<decltype(cbrt((unsigned long) 0)),
+ double>::value), "");
+ static_assert((std::is_same<decltype(cbrt((long long) 0)), double>::value),
+ "");
+ static_assert((std::is_same<decltype(cbrt((unsigned long long) 0)),
+ double>::value), "");
+ static_assert((std::is_same<decltype(cbrt((double) 0)), double>::value),
+ "");
+ static_assert((std::is_same<decltype(cbrt((long double) 0)),
+ long double>::value), "");
static_assert((std::is_same<decltype(cbrtf(0)), float>::value), "");
static_assert((std::is_same<decltype(cbrtl(0)), long double>::value), "");
- static_assert((std::is_same<decltype(cbrt(Ambiguous())), Ambiguous>::value), "");
- assert(cbrt(1) == 1);
+ static_assert((std::is_same<decltype(cbrt(Ambiguous())), Ambiguous>::value),
+ "");
+ assert(truncate_fp(cbrt(1)) == 1);
+
}
void test_copysign()
Modified: libcxx/trunk/test/std/numerics/c.math/cmath.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/c.math/cmath.pass.cpp?rev=349387&r1=349386&r2=349387&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/c.math/cmath.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/c.math/cmath.pass.cpp Mon Dec 17 12:17:43 2018
@@ -16,6 +16,7 @@
#include "test_macros.h"
#include "hexfloat.h"
+#include "truncate_fp.h"
// convertible to int/float/double/etc
template <class T, int N=0>
@@ -860,7 +861,7 @@ void test_cbrt()
static_assert((std::is_same<decltype(std::cbrtf(0)), float>::value), "");
static_assert((std::is_same<decltype(std::cbrtl(0)), long double>::value), "");
static_assert((std::is_same<decltype(cbrt(Ambiguous())), Ambiguous>::value), "");
- assert(std::cbrt(1) == 1);
+ assert(truncate_fp(std::cbrt(1)) == 1);
}
void test_copysign()
Modified: libcxx/trunk/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp?rev=349387&r1=349386&r2=349387&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp Mon Dec 17 12:17:43 2018
@@ -15,6 +15,8 @@
#include <random>
#include <cassert>
+#include "truncate_fp.h"
+
int main()
{
{
@@ -22,35 +24,35 @@ int main()
typedef float F;
E r;
F f = std::generate_canonical<F, 0>(r);
- assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1)));
+ assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
}
{
typedef std::minstd_rand0 E;
typedef float F;
E r;
F f = std::generate_canonical<F, 1>(r);
- assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1)));
+ assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
}
{
typedef std::minstd_rand0 E;
typedef float F;
E r;
F f = std::generate_canonical<F, std::numeric_limits<F>::digits - 1>(r);
- assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1)));
+ assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
}
{
typedef std::minstd_rand0 E;
typedef float F;
E r;
F f = std::generate_canonical<F, std::numeric_limits<F>::digits>(r);
- assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1)));
+ assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
}
{
typedef std::minstd_rand0 E;
typedef float F;
E r;
F f = std::generate_canonical<F, std::numeric_limits<F>::digits + 1>(r);
- assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1)));
+ assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
}
{
@@ -58,43 +60,43 @@ int main()
typedef double F;
E r;
F f = std::generate_canonical<F, 0>(r);
- assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1)));
+ assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
}
{
typedef std::minstd_rand0 E;
typedef double F;
E r;
F f = std::generate_canonical<F, 1>(r);
- assert(f == (16807 - E::min()) / (E::max() - E::min() + F(1)));
+ assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
}
{
typedef std::minstd_rand0 E;
typedef double F;
E r;
F f = std::generate_canonical<F, std::numeric_limits<F>::digits - 1>(r);
- assert(f ==
+ assert(f == truncate_fp(
(16807 - E::min() +
(282475249 - E::min()) * (E::max() - E::min() + F(1))) /
- ((E::max() - E::min() + F(1)) * (E::max() - E::min() + F(1))));
+ ((E::max() - E::min() + F(1)) * (E::max() - E::min() + F(1)))));
}
{
typedef std::minstd_rand0 E;
typedef double F;
E r;
F f = std::generate_canonical<F, std::numeric_limits<F>::digits>(r);
- assert(f ==
+ assert(f == truncate_fp(
(16807 - E::min() +
(282475249 - E::min()) * (E::max() - E::min() + F(1))) /
- ((E::max() - E::min() + F(1)) * (E::max() - E::min() + F(1))));
+ ((E::max() - E::min() + F(1)) * (E::max() - E::min() + F(1)))));
}
{
typedef std::minstd_rand0 E;
typedef double F;
E r;
F f = std::generate_canonical<F, std::numeric_limits<F>::digits + 1>(r);
- assert(f ==
+ assert(f == truncate_fp(
(16807 - E::min() +
(282475249 - E::min()) * (E::max() - E::min() + F(1))) /
- ((E::max() - E::min() + F(1)) * (E::max() - E::min() + F(1))));
+ ((E::max() - E::min() + F(1)) * (E::max() - E::min() + F(1)))));
}
}
Modified: libcxx/trunk/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp?rev=349387&r1=349386&r2=349387&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp Mon Dec 17 12:17:43 2018
@@ -20,6 +20,7 @@
#include <cassert>
#include "test_macros.h"
+#include "truncate_fp.h"
int main()
{
@@ -41,7 +42,7 @@ int main()
{
std::chrono::duration<int, std::ratio<2, 3> > s1(30);
std::chrono::duration<double, std::ratio<3, 5> > s2(5);
- assert(s1 / s2 == 20./3);
+ assert(s1 / s2 == truncate_fp(20./3));
}
#if TEST_STD_VER >= 11
{
Added: libcxx/trunk/test/support/truncate_fp.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/truncate_fp.h?rev=349387&view=auto
==============================================================================
--- libcxx/trunk/test/support/truncate_fp.h (added)
+++ libcxx/trunk/test/support/truncate_fp.h Mon Dec 17 12:17:43 2018
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+inline long double truncate_fp(long double val) {
+ volatile long double sink = val;
+ return sink;
+}
+
+inline double truncate_fp(double val) {
+ volatile double sink = val;
+ return sink;
+}
+
+inline float truncate_fp(float val) {
+ volatile float sink = val;
+ return sink;
+}
More information about the libcxx-commits
mailing list