[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master ee120a2d 1/3: Improve documentation; add 'con
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master ee120a2d 1/3: Improve documentation; add 'const' |
Date: |
Fri, 27 May 2022 20:49:10 -0400 (EDT) |
branch: master
commit ee120a2d83083727248f09c66f4a230784b484da
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Improve documentation; add 'const'
Added 'const' in the hope of making the expression likelier to be
evaluated at compile time.
As an extension, gcc would allow
- static T const z0 = std::pow
+ constexpr T z0 = std::pow
but not all compilers support that.
---
tn_range.tpp | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/tn_range.tpp b/tn_range.tpp
index 0e8d9793..5bcb1069 100644
--- a/tn_range.tpp
+++ b/tn_range.tpp
@@ -175,9 +175,17 @@ namespace
static_assert(std::is_floating_point_v<T>);
bool operator()(T t)
{
- // SOMEDAY !! nonstd::power() [SGI extension] may be
- // preferable, because std::pow() might not be exact.
- static T z0 = std::pow
+ // Here, nonstd::power() isn't preferable to pow(). This
+ // value needn't be exact, because no end user will enter
+ // a value exactly equal to 2^53 (e.g.). Furthermore, all
+ // releases compiled with gcc are optimized, so gcc should
+ // perform this constant calculation at compile time.
+ // Thus, the historical untrustworthiness of MinGW-w64's
+ // pow(), e.g.:
+ // pow(100.0, 2.0) != 100.0
+ // pow(2.0, 0.5) != sqrt(2.0)
+ // shouldn't matter.
+ static T const z0 = std::pow
(static_cast<T>(std::numeric_limits<T>::radix)
,static_cast<T>(std::numeric_limits<T>::digits)
);