[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 1bead9e 08/13: Purge unwanted, commented-out
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 1bead9e 08/13: Purge unwanted, commented-out code |
Date: |
Fri, 9 Apr 2021 18:42:37 -0400 (EDT) |
branch: master
commit 1bead9e42738233ecc710202cb8c172ca7a56789
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Purge unwanted, commented-out code
Commit 2a3d961046af8 of 20210406T2020Z shows that addition-chain
exponentiation is eight times as fast as std::pow() for calculating
positive-integer powers of ten. There's no reason to consider using
std::pow() instead for this purpose, and good reason not to hope that
std::pow() will pick as good an algorithm--see:
https://lists.nongnu.org/archive/html/lmi/2016-12/msg00049.html
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78851
https://gcc.gnu.org/legacy-ml/gcc-help/2018-09/msg00034.html
---
round_to.hpp | 39 ---------------------------------------
1 file changed, 39 deletions(-)
diff --git a/round_to.hpp b/round_to.hpp
index da2e286..4502878 100644
--- a/round_to.hpp
+++ b/round_to.hpp
@@ -55,7 +55,6 @@ using max_prec_real = long double;
namespace detail
{
-#if 1
/// Raise 'r' to the integer power 'n'.
///
/// Motivation: To raise an integer-valued real to a positive integer
@@ -96,44 +95,6 @@ RealType int_pow(RealType r, int n)
return nonstd::power(r, n);
}
}
-
-#else // 0
-
-/// Raise an integer-valued real to an integer power.
-///
-/// Motivation: calculate accurate powers of ten. See:
-/// https://lists.nongnu.org/archive/html/lmi/2016-12/msg00049.html
-/// Library authors often optimize pow() for integral exponents,
-/// using multiplication rather than a transcendental calculation.
-/// When 'r' is exactly representable, positive integral powers
-/// returned by a high-quality std::pow() are likely to be exact if
-/// they are exactly representable, or otherwise as accurate as they
-/// can be; but for negative integral powers this integral-exponent
-/// "optimization" may very well reduce accuracy, e.g., if 10^-3 is
-/// calculated as (0.1 * 0.1 * 0.1). Because the positive-exponent
-/// case is likely to be treated ideally by the library author, when
-/// 'n' is negative this function calls std::pow() to calculate the
-/// positive power and returns the reciprocal: 1 / (10 * 10 * 10)
-/// in the preceding example.
-
-template<typename RealType>
-RealType int_pow(RealType r, int n)
-{
- if(0 == n)
- {
- return RealType(1.0);
- }
- else if(n < 0)
- {
- return RealType(1.0) / std::pow(r, -n);
- }
- else
- {
- return std::pow(r, n);
- }
-}
-
-#endif // 0
} // namespace detail
inline rounding_style& default_rounding_style()
- [lmi-commits] [lmi] master updated (8aa09b9 -> a32cee0), Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 79741b1 01/13: Assert a precondition more consistently, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 358c5c9 06/13: Modernize, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master edb098f 02/13: Strengthen unit tests, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 2a3d961 03/13: Measure cost of a needless transcendental calculation, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 6bc828a 05/13: Realign, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 290dc89 10/13: Remove a source of inaccuracy [285], Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master a32cee0 13/13: Hoist a division, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 1e49ee3 04/13: Revise 'round_to' documentation [286], Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 1bead9e 08/13: Purge unwanted, commented-out code,
Greg Chicares <=
- [lmi-commits] [lmi] master ce9ed5c 07/13: Add an inchoate test of power-of-ten scaling, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 858d037 09/13: Include appropriate headers, and say why they're included, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master ca63009 11/13: Expunge an obsolete comment, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master c41faec 12/13: Resolve a marked defect [284], Greg Chicares, 2021/04/09