[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master b954393 2/8: Don't hard-code sqrt(2)
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master b954393 2/8: Don't hard-code sqrt(2) |
Date: |
Fri, 30 Jul 2021 16:14:47 -0400 (EDT) |
branch: master
commit b954393f338f078bd675be8c17ac45c4d59b08fa
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Don't hard-code sqrt(2)
Calling sqrt() seems preferable. See this IEEE publication:
https://ieeexplore.ieee.org/document/910638
| The IEEE 754 standard for floating-point arithmetic requires that the
| four arithmetic operations and the square root should be correctly
| rounded.
It's not entirely clear what it means to "require" that something
"should" be done. Presumably a mandative subjunctive is intended:
requires that...the square root be correctly rounded
["should" inserted only because UK English lacks the subjunctive]
because the IEEE 754 standard itself groups squareRoot in section
"5.4.1 Arithmetic operations"
along with {+,-,×,÷}, whereas another section
"Table 9.1 — Recommended correctly rounded functions"
lists functions, like reciprocal-sqrt and the usual transcendentals,
for which correct rounding would be ideal but was not originally
required (the authors go on to show that it is actually feasible).
---
zero_test.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/zero_test.cpp b/zero_test.cpp
index dc88d6b..1926b23 100644
--- a/zero_test.cpp
+++ b/zero_test.cpp
@@ -29,7 +29,7 @@
#include "test_tools.hpp"
#include <cfloat> // DECIMAL_DIG
-#include <cmath> // exp(), fabs(), log(), pow()
+#include <cmath> // exp(), fabs(), log(), pow(), sqrt()
#include <limits>
#include <sstream>
@@ -882,7 +882,7 @@ void test_various_functions()
test_a_function (f03, root_03, -0.01, 0.8, 1.0e-15, __LINE__);
auto f04 = [](double x) {return std::pow(x, 2.0) - 2.0;};
- auto root_04 = 1.4142135623730951;
+ auto root_04 = std::sqrt(2.0);
test_a_decimal_function(f04, root_04, 0.0 , 2.0, 17 , __LINE__, 10);
test_a_function (f04, root_04, 0.0 , 2.0, 1.0e-15, __LINE__);
- [lmi-commits] [lmi] master updated (028b454 -> 5d4f506), Greg Chicares, 2021/07/30
- [lmi-commits] [lmi] master 828ff21 1/8: Renumber some unit tests, Greg Chicares, 2021/07/30
- [lmi-commits] [lmi] master 0113a5d 3/8: Test three examples from a textbook, Greg Chicares, 2021/07/30
- [lmi-commits] [lmi] master 4bc5b1f 4/8: Make bounds and tolerance match textbook examples better, Greg Chicares, 2021/07/30
- [lmi-commits] [lmi] master b954393 2/8: Don't hard-code sqrt(2),
Greg Chicares <=
- [lmi-commits] [lmi] master de32b80 7/8: Add an all-platform unit-test script, Greg Chicares, 2021/07/30
- [lmi-commits] [lmi] master 5d4f506 8/8: Record speed measurements, Greg Chicares, 2021/07/30
- [lmi-commits] [lmi] master cf516cc 6/8: Remove code added in the last commit to support its conclusions, Greg Chicares, 2021/07/30
- [lmi-commits] [lmi] master ac5731f 5/8: Controvert a published claim, Greg Chicares, 2021/07/30