lmi-commits
[Top][All Lists]
Advanced

[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()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]