From 11afeee44535390ff9d6fd475ebc72b0f4ed59aa Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sat, 7 Dec 2019 19:20:04 +0000 Subject: [PATCH] Change cpp_dec_float to not use long double unless specifically asked to do so. --- .../boost/multiprecision/cpp_dec_float.hpp | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/include/boost/multiprecision/cpp_dec_float.hpp b/include/boost/multiprecision/cpp_dec_float.hpp index 900c058c..b2f83a52 100644 --- a/include/boost/multiprecision/cpp_dec_float.hpp +++ b/include/boost/multiprecision/cpp_dec_float.hpp @@ -78,7 +78,7 @@ class cpp_dec_float public: typedef mpl::list signed_types; typedef mpl::list unsigned_types; - typedef mpl::list float_types; + typedef mpl::list float_types; typedef ExponentType exponent_type; static const boost::int32_t cpp_dec_float_radix = 10L; @@ -162,8 +162,8 @@ class cpp_dec_float cpp_dec_float::half(); cpp_dec_float::double_min(); cpp_dec_float::double_max(); - cpp_dec_float::long_double_max(); - cpp_dec_float::long_double_min(); + //cpp_dec_float::long_double_max(); + //cpp_dec_float::long_double_min(); cpp_dec_float::long_long_max(); cpp_dec_float::long_long_min(); cpp_dec_float::ulong_long_max(); @@ -175,6 +175,18 @@ class cpp_dec_float static initializer init; + struct long_double_initializer + { + long_double_initializer() + { + cpp_dec_float::long_double_max(); + cpp_dec_float::long_double_min(); + } + void do_nothing() {} + }; + + static long_double_initializer linit; + public: // Constructors cpp_dec_float() BOOST_MP_NOEXCEPT_IF(noexcept(array_type())) : data(), @@ -331,20 +343,20 @@ class cpp_dec_float static const cpp_dec_float& double_min() { init.do_nothing(); - static cpp_dec_float val(static_cast((std::numeric_limits::min)())); + static cpp_dec_float val((std::numeric_limits::min)()); return val; } static const cpp_dec_float& double_max() { init.do_nothing(); - static cpp_dec_float val(static_cast((std::numeric_limits::max)())); + static cpp_dec_float val((std::numeric_limits::max)()); return val; } static const cpp_dec_float& long_double_min() { - init.do_nothing(); + linit.do_nothing(); #ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS static cpp_dec_float val(static_cast((std::numeric_limits::min)())); #else @@ -355,7 +367,7 @@ class cpp_dec_float static const cpp_dec_float& long_double_max() { - init.do_nothing(); + linit.do_nothing(); #ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS static cpp_dec_float val(static_cast((std::numeric_limits::max)())); #else @@ -434,7 +446,8 @@ class cpp_dec_float return *this; } - cpp_dec_float& operator=(long double v); + template + typename boost::enable_if_c::value, cpp_dec_float&>::type operator=(Float v); cpp_dec_float& operator=(const char* v) { @@ -624,6 +637,8 @@ class cpp_dec_float template typename cpp_dec_float::initializer cpp_dec_float::init; +template +typename cpp_dec_float::long_double_initializer cpp_dec_float::linit; template const boost::int32_t cpp_dec_float::cpp_dec_float_radix; @@ -1564,6 +1579,7 @@ double cpp_dec_float::extract_double() const } std::stringstream ss; + ss.imbue(std::locale::classic()); ss << str(std::numeric_limits::digits10 + (2 + 1), std::ios_base::scientific); @@ -1610,6 +1626,7 @@ long double cpp_dec_float::extract_long_doubl } std::stringstream ss; + ss.imbue(std::locale::classic()); ss << str(std::numeric_limits::digits10 + (2 + 1), std::ios_base::scientific); @@ -2249,7 +2266,8 @@ cpp_dec_float::cpp_dec_float(const double man } template -cpp_dec_float& cpp_dec_float::operator=(long double a) +template +typename boost::enable_if_c::value, cpp_dec_float&>::type cpp_dec_float::operator=(Float a) { // Christopher Kormanyos's original code used a cast to boost::long_long_type here, but that fails // when long double has more digits than a boost::long_long_type. @@ -2275,7 +2293,7 @@ cpp_dec_float& cpp_dec_float -inline void eval_convert_to(long double* result, cpp_dec_float& val) +inline void eval_convert_to(long double* result, const cpp_dec_float& val) { *result = val.extract_long_double(); } +template +inline void eval_convert_to(double* result, const cpp_dec_float& val) +{ + *result = val.extract_double(); +} // // Non member function support: