[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 6327528 6/8: Use C++11 overloads for C99 <mat
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 6327528 6/8: Use C++11 overloads for C99 <math.h> functions |
Date: |
Mon, 24 Apr 2017 16:43:51 -0400 (EDT) |
branch: master
commit 6327528aecf7c993494a5309a78e6381e9b80dbf
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Use C++11 overloads for C99 <math.h> functions
The removed comment meant that a C++98 toolchain would translate
std::fabs()
into a call to
double fabs(double);
Now, however, with C++14, calling std::fabs() with a long double
argument actually calls an override equivalent to fabsl().
---
numeric_io_traits.hpp | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/numeric_io_traits.hpp b/numeric_io_traits.hpp
index 43ddb8b..9fb5c98 100644
--- a/numeric_io_traits.hpp
+++ b/numeric_io_traits.hpp
@@ -28,7 +28,7 @@
#include "ieee754.hpp" // is_infinite<>()
#include <algorithm> // std::max()
-#include <cmath> // C99 functions fabsl(), log10l(),
strtold()
+#include <cmath> // std::fabs(), std::log10()
#include <cstdlib> // std::strto*()
#include <cstring> // std::strcmp(), std::strlen()
#include <limits>
@@ -53,12 +53,6 @@
/// Notes: Truncation by static_cast<int> is appropriate because the
/// result is constrained to be nonnegative. If negative results were
/// wanted, it would be necessary to round toward negative infinity.
-///
-/// Because many compilers in 2004 still don't implement C++98 26.5/6
-/// correctly, C99 functions fabsl() and log10l() are used here. It is
-/// less likely that these are incorrect than that the C++ overloads
-/// are missing, which would cause std::fabs() and std::log10() to be
-/// invoked for type long double.
template<typename T>
inline int floating_point_decimals(T t)
@@ -79,8 +73,8 @@ inline int floating_point_decimals(T t)
{
return 0;
}
- long double z = std::numeric_limits<T>::epsilon() * fabsl(t);
- return std::max(0, static_cast<int>(-log10l(z)));
+ long double z = std::numeric_limits<T>::epsilon() * std::fabs(t);
+ return std::max(0, static_cast<int>(-std::log10(z)));
}
/// Simplify a formatted floating-point number.
@@ -385,7 +379,7 @@ template<> struct numeric_conversion_traits<long double>
#if defined LMI_MSVCRT
{return strtoFDL_msvc(nptr, endptr);}
#else // !defined LMI_MSVCRT
- {return strtold(nptr, endptr);}
+ {return std::strtold(nptr, endptr);}
#endif // !defined LMI_MSVCRT
};
- [lmi-commits] [lmi] master updated (29808d8 -> 2f1cecc), Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master 27584b1 1/8: Use is_signed to differentiate between signed and unsigned, Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master 895c823 3/8: Do not make variable initialized with ldexp() constexpr, Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master b5fe551 4/8: Write 'const' after the type it modifies, Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master a9c5ed5 7/8: Resolve a marked defect [389], Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master 6327528 6/8: Use C++11 overloads for C99 <math.h> functions,
Greg Chicares <=
- [lmi-commits] [lmi] master 461c143 2/8: Replace boost::numeric_cast with bourn_cast, Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master dea45f1 5/8: Avoid 'static constexpr' locals, Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master 2f1cecc 8/8: Explicitly qualify std::fabs(), Greg Chicares, 2017/04/24