diff --git a/test/std/depr/depr.c.headers/math_h.pass.cpp b/test/std/depr/depr.c.headers/math_h.pass.cpp index 7e1b2d110..e8341a07f 100644 --- a/test/std/depr/depr.c.headers/math_h.pass.cpp +++ b/test/std/depr/depr.c.headers/math_h.pass.cpp @@ -14,6 +14,7 @@ #include #include "hexfloat.h" +#include "truncate_fp.h" // convertible to int/float/double/etc template @@ -807,23 +808,31 @@ void test_atanh() assert(atanh(0) == 0); } -void test_cbrt() -{ - static_assert((std::is_same::value), ""); - static_assert((std::is_same::value), ""); - static_assert((std::is_same::value), ""); - static_assert((std::is_same::value), ""); - static_assert((std::is_same::value), ""); - static_assert((std::is_same::value), ""); - static_assert((std::is_same::value), ""); - static_assert((std::is_same::value), ""); - static_assert((std::is_same::value), ""); - static_assert((std::is_same::value), ""); - static_assert((std::is_same::value), ""); +void test_cbrt() { + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), + ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), + ""); + static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); - static_assert((std::is_same::value), ""); - assert(cbrt(1) == 1); + static_assert((std::is_same::value), + ""); + assert(truncate_fp(cbrt(1)) == 1); + } void test_copysign() diff --git a/test/std/numerics/c.math/cmath.pass.cpp b/test/std/numerics/c.math/cmath.pass.cpp index cc535e374..b02bdbe64 100644 --- a/test/std/numerics/c.math/cmath.pass.cpp +++ b/test/std/numerics/c.math/cmath.pass.cpp @@ -16,6 +16,7 @@ #include "test_macros.h" #include "hexfloat.h" +#include "truncate_fp.h" // convertible to int/float/double/etc template @@ -860,7 +861,7 @@ void test_cbrt() static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); - assert(std::cbrt(1) == 1); + assert(truncate_fp(std::cbrt(1)) == 1); } void test_copysign() diff --git a/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp b/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp index 7433e28e4..df2acbe9e 100644 --- a/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp +++ b/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp @@ -15,6 +15,8 @@ #include #include +#include "truncate_fp.h" + int main() { { @@ -22,35 +24,35 @@ int main() typedef float F; E r; F f = std::generate_canonical(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(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::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::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::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(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(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::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::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::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))))); } } diff --git a/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp b/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp index 561516b66..4c4895b2a 100644 --- a/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp +++ b/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp @@ -20,6 +20,7 @@ #include #include "test_macros.h" +#include "truncate_fp.h" int main() { @@ -41,7 +42,7 @@ int main() { std::chrono::duration > s1(30); std::chrono::duration > s2(5); - assert(s1 / s2 == 20./3); + assert(s1 / s2 == truncate_fp(20./3)); } #if TEST_STD_VER >= 11 { diff --git a/test/support/truncate_fp.h b/test/support/truncate_fp.h new file mode 100644 index 000000000..83b2b2cff --- /dev/null +++ b/test/support/truncate_fp.h @@ -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; +}