lmi-commits
[Top][All Lists]
Advanced

[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
 };
 



reply via email to

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