[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master b2deccf 4/5: Prefer std::scalbn to std::pow f
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master b2deccf 4/5: Prefer std::scalbn to std::pow for integer powers of FP radix |
Date: |
Sun, 23 Apr 2017 15:37:32 -0400 (EDT) |
branch: master
commit b2deccf0965fdf2ba623381d8a0fe686d4be2f04
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Prefer std::scalbn to std::pow for integer powers of FP radix
---
value_cast_test.cpp | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/value_cast_test.cpp b/value_cast_test.cpp
index 863e906..3bebc75 100644
--- a/value_cast_test.cpp
+++ b/value_cast_test.cpp
@@ -28,7 +28,7 @@
#include <boost/lexical_cast.hpp>
-#include <cmath> // std::pow()
+#include <cmath> // std::scalbn()
#include <cstring> // std::strcpy(), std::strcmp
#include <istream>
#include <limits>
@@ -328,9 +328,9 @@ int extra_tests0()
// A big number that must be representable as a finite
// floating-point number [18.2.1.2/27].
- double big = std::pow
- (static_cast<double>(std::numeric_limits<double>::radix)
- ,static_cast<double>(std::numeric_limits<double>::max_exponent - 1)
+ double big = std::scalbn
+ (1.0
+ ,std::numeric_limits<double>::max_exponent - 1
);
// Using libmingwex's strtod() to convert a really big number
@@ -347,7 +347,7 @@ int extra_tests0()
// Initialize 'nptr' to a string representation of
// FLT_RADIX^(DBL_MAX_EXP-1)
// produced by snprintf(), verifiable thus:
- // double big = pow(FLT_RADIX, DBL_MAX_EXP - 1.0);
+ // double big = std::scalbn(1.0, DBL_MAX_EXP - 1.0);
// snprintf(buffer, buffer_length, "%.*f", 0, big);
char const* nptr =
// 12345678901234567890123456789012345678901234567890 <-- 50 digits/line
@@ -365,9 +365,9 @@ int extra_tests0()
// A small number that must be representable as a normalized
// floating-point number [18.2.1.2/23].
- double small = std::pow
- (static_cast<double>(std::numeric_limits<double>::radix)
- ,static_cast<double>(std::numeric_limits<double>::min_exponent)
+ double small = std::scalbn
+ (1.0
+ ,std::numeric_limits<double>::min_exponent
// TODO ?? Why doesn't this work with '- 1' appended?
// ,static_cast<double>(std::numeric_limits<double>::min_exponent - 1)
);