summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/numerics/numeric.ops
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2019-06-18 18:13:54 +0000
committerMarshall Clow <mclow.lists@gmail.com>2019-06-18 18:13:54 +0000
commit8dc6840f1c91a0a0442afa841bff5123efb44334 (patch)
tree05a11b036ef82c29d1df6f505cc6eca77cfccb3b /libcxx/test/std/numerics/numeric.ops
parent032b54f8e87f4fa380f2e83c8fbcd9b14d50f4e0 (diff)
downloadbcm5719-llvm-8dc6840f1c91a0a0442afa841bff5123efb44334.tar.gz
bcm5719-llvm-8dc6840f1c91a0a0442afa841bff5123efb44334.zip
Fix the floating point version of midpoint. It wasn't constexpr, among other things. Add more tests. As a drive-by, the LCD implementation had a class named '__abs' which did a 'absolute value to a common-type' conversion. Rename that to be '__ct_abs'.
llvm-svn: 363714
Diffstat (limited to 'libcxx/test/std/numerics/numeric.ops')
-rw-r--r--libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.float.pass.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.float.pass.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.float.pass.cpp
index 1a967f7a26e..7d98348881b 100644
--- a/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.float.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.float.pass.cpp
@@ -43,11 +43,11 @@ void fp_test()
constexpr T minV = std::numeric_limits<T>::min();
// Things that can be compared exactly
- assert((std::midpoint(T(0), T(0)) == T(0)));
- assert((std::midpoint(T(2), T(4)) == T(3)));
- assert((std::midpoint(T(4), T(2)) == T(3)));
- assert((std::midpoint(T(3), T(4)) == T(3.5)));
- assert((std::midpoint(T(0), T(0.4)) == T(0.2)));
+ static_assert((std::midpoint(T(0), T(0)) == T(0)), "");
+ static_assert((std::midpoint(T(2), T(4)) == T(3)), "");
+ static_assert((std::midpoint(T(4), T(2)) == T(3)), "");
+ static_assert((std::midpoint(T(3), T(4)) == T(3.5)), "");
+ static_assert((std::midpoint(T(0), T(0.4)) == T(0.2)), "");
// Things that can't be compared exactly
constexpr T pct = fp_error_pct<T>();
@@ -70,6 +70,17 @@ void fp_test()
assert((fptest_close_pct(std::midpoint(T(0), minV), minV/2, pct)));
assert((fptest_close_pct(std::midpoint(maxV, maxV), maxV, pct)));
assert((fptest_close_pct(std::midpoint(minV, minV), minV, pct)));
+ assert((fptest_close_pct(std::midpoint(maxV, minV), maxV/2, pct)));
+ assert((fptest_close_pct(std::midpoint(minV, maxV), maxV/2, pct)));
+
+// Near the min and the max
+ assert((fptest_close_pct(std::midpoint(maxV*T(0.75), maxV*T(0.50)), maxV*T(0.625), pct)));
+ assert((fptest_close_pct(std::midpoint(maxV*T(0.50), maxV*T(0.75)), maxV*T(0.625), pct)));
+ assert((fptest_close_pct(std::midpoint(minV*T(2), minV*T(8)), minV*T(5), pct)));
+
+// Big numbers of different signs
+ assert((fptest_close_pct(std::midpoint(maxV*T( 0.75), maxV*T(-0.5)), maxV*T( 0.125), pct)));
+ assert((fptest_close_pct(std::midpoint(maxV*T(-0.75), maxV*T( 0.5)), maxV*T(-0.125), pct)));
// Denormalized values
// TODO
OpenPOWER on IntegriCloud