Use std:: <cmath> functions, except on msvc-11.0 and below

This commit is contained in:
Peter Dimov
2020-11-23 05:20:28 +02:00
parent 731ea46ba8
commit 7ea0caa72c

View File

@@ -32,7 +32,6 @@
#include <cstddef>
#include <cstring>
#include <cmath>
#include <math.h>
#if defined(_MSC_VER) && _MSC_VER < 1800
# include <float.h>
#endif
@@ -51,29 +50,39 @@ namespace boost {
return true;
}
namespace lcast_math
{
#if defined(_MSC_VER) && _MSC_VER < 1800
template<class T> T copysign( T x, T y )
{
return static_cast<T>( _copysign( static_cast<double>( x ), static_cast<double>( y ) ) );
}
template<class T> T copysign( T x, T y )
{
return static_cast<T>( _copysign( static_cast<double>( x ), static_cast<double>( y ) ) );
}
template<class T> bool isnan( T x )
{
return _isnan( static_cast<double>( x ) ) != 0;
}
template<class T> bool isnan( T x )
{
return _isnan( static_cast<double>( x ) ) != 0;
}
template<class T> bool isinf( T x )
{
return ( _fpclass( static_cast<double>( x ) ) & ( _FPCLASS_PINF | _FPCLASS_NINF ) ) != 0;
}
template<class T> bool isinf( T x )
{
return ( _fpclass( static_cast<double>( x ) ) & ( _FPCLASS_PINF | _FPCLASS_NINF ) ) != 0;
}
template<class T> bool signbit( T x )
{
return _copysign( 1.0, static_cast<double>( x ) ) < 0.0;
}
template<class T> bool signbit( T x )
{
return _copysign( 1.0, static_cast<double>( x ) ) < 0.0;
}
#else
using ::copysign; // it is what it is
using std::isnan;
using std::isinf;
using std::signbit;
#endif
} // namespace lcast_math
/* Returns true and sets the correct value if found NaN or Inf. */
template <class CharT, class T>
@@ -105,7 +114,7 @@ namespace boost {
}
if( !has_minus ) value = std::numeric_limits<T>::quiet_NaN();
else value = copysign(std::numeric_limits<T>::quiet_NaN(), static_cast<T>(-1));
else value = lcast_math::copysign(std::numeric_limits<T>::quiet_NaN(), static_cast<T>(-1));
return true;
} else if (
( /* 'INF' or 'inf' */
@@ -132,12 +141,9 @@ namespace boost {
, const CharT* lc_nan
, const CharT* lc_infinity) BOOST_NOEXCEPT
{
#if defined(__GNUC__)
using std::signbit;
#endif
const CharT minus = lcast_char_constants<CharT>::minus;
if (isnan(value)) {
if (signbit(value)) {
if (lcast_math::isnan(value)) {
if (lcast_math::signbit(value)) {
*begin = minus;
++ begin;
}
@@ -145,8 +151,8 @@ namespace boost {
std::memcpy(begin, lc_nan, 3 * sizeof(CharT));
end = begin + 3;
return true;
} else if (isinf(value)) {
if (signbit(value)) {
} else if (lcast_math::isinf(value)) {
if (lcast_math::signbit(value)) {
*begin = minus;
++ begin;
}