[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 50009ece 10/10: x⋅(1+ε) ≢ nextafter(x) [264]
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 50009ece 10/10: x⋅(1+ε) ≢ nextafter(x) [264] |
Date: |
Mon, 20 Jun 2022 19:16:26 -0400 (EDT) |
branch: master
commit 50009ece2389ce2a916346c22bbb04013aeda633
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
x⋅(1+ε) ≢ nextafter(x) [264]
---
round_to_test.cpp | 25 +++++++------------------
1 file changed, 7 insertions(+), 18 deletions(-)
diff --git a/round_to_test.cpp b/round_to_test.cpp
index 54dd2868..ff061bb5 100644
--- a/round_to_test.cpp
+++ b/round_to_test.cpp
@@ -192,8 +192,8 @@ bool round_to_test::test_one_case
max_prec_real abs_error = std::fabs(observed - expected);
max_prec_real rel_error = relative_error(observed, expected);
- // In general, we can't hope for the relative error to be less than
- // epsilon for the floating-point type being rounded. Suppose a
+ // In general, we can't hope for the absolute error to be less than
+ // one ulp for the floating-point type being rounded. Suppose a
// variable gets its value from a floating literal; 2.13.3/1 says
// "If the scaled value is in the range of representable values
// for its type, the result is the scaled value if representable,
@@ -205,7 +205,7 @@ bool round_to_test::test_one_case
// direction, as can an expression like '5.0 / 1000.0'. C99 (but
// not C++) requires evaluation of non-static floating-point
// constants as if at runtime [F.7.4/1].
- max_prec_real tolerance = std::numeric_limits<RealType>::epsilon();
+ max_prec_real tolerance = delta_outward(unrounded);
// If the decimal scaling factor is not unity, then either it or
// its reciprocal has no exact finite binary representation. Such
@@ -221,23 +221,12 @@ bool round_to_test::test_one_case
// identity hold at runtime unless __STDC_IEC_559__ is defined.
if(0 != decimals)
{
- // 'tolerance' is of the maximum-precision floating-point
- // type so that it can more closely represent this quantity for
- // types with less precision, without letting the cross-product
- // term epsilon**2 vanish.
- //
- // TODO ?? Shouldn't one epsilon here be epsilon of
- // max-precision-real type, as shown in a comment?
- // But consider using std::nextafter instead of (1+epsilon).
- RealType const unity = 1;
tolerance =
- (unity + std::numeric_limits<RealType>::epsilon())
- * (unity + std::numeric_limits<RealType>::epsilon())
-// * (unity + std::numeric_limits<max_prec_real>::epsilon())
- - unity
- ;
+ 2 * delta_outward (unrounded)
+ + delta_outward<max_prec_real>(unrounded)
+ ;
}
- bool error_is_within_tolerance = rel_error <= tolerance;
+ bool error_is_within_tolerance = abs_error <= tolerance;
if(!error_is_within_tolerance)
{
- [lmi-commits] [lmi] master updated (876d4b5b -> 50009ece), Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master e986f0c9 02/10: Specify types more explicitly in unit test, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master a6f2830d 01/10: Explain the necessity of a certain cast, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 3c9845b4 06/10: State the purpose of a particular unit test, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 8f5b6960 04/10: Demonstrate object sizes in unit test, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 1744d568 07/10: Regularize every mention of nextafter(), Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master e711587c 08/10: Expunge a workaround for an obsolete compiler, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 168e9a70 03/10: Specify a constant more clearly, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 7258e4ae 05/10: Establish and test explicit postconditions, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 50009ece 10/10: x⋅(1+ε) ≢ nextafter(x) [264],
Greg Chicares <=
- [lmi-commits] [lmi] master e7278f90 09/10: Add some functions to complement std::nextafter(), Greg Chicares, 2022/06/20