Skip to content

Commit cf631fa

Browse files
committed
Preliminary re-run of all tests
1 parent 3c4cd10 commit cf631fa

File tree

1 file changed

+52
-51
lines changed

1 file changed

+52
-51
lines changed

include/boost/multiprecision/cpp_double_fp.hpp

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@
1010
#ifndef BOOST_MP_CPP_DOUBLE_FP_2021_06_05_HPP
1111
#define BOOST_MP_CPP_DOUBLE_FP_2021_06_05_HPP
1212

13-
#if (defined(_MSC_VER) && (_MSC_VER <= 1900))
14-
#pragma warning(push)
15-
#pragma warning (disable : 4814)
13+
#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS)
14+
#define BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
1615
#endif
1716

18-
#include <limits>
19-
#include <string>
20-
#include <type_traits>
21-
2217
#include <boost/multiprecision/cpp_dec_float.hpp>
2318
#include <boost/multiprecision/cpp_df_qf/cpp_df_qf_detail.hpp>
2419
#include <boost/multiprecision/detail/float_string_cvt.hpp>
@@ -42,6 +37,10 @@
4237
#include <boost/math/special_functions/gamma.hpp>
4338
#endif
4439

40+
#include <limits>
41+
#include <string>
42+
#include <type_traits>
43+
4544
#if (defined(__clang__) && (__clang_major__ <= 9))
4645
#define BOOST_MP_DF_QF_NUM_LIMITS_CLASS_TYPE struct
4746
#else
@@ -244,8 +243,8 @@ class cpp_double_fp_backend
244243

245244
// Constructors from integers
246245
template <typename SignedIntegralType,
247-
typename ::std::enable_if<( boost::multiprecision::detail::is_integral<SignedIntegralType>::value
248-
&& !boost::multiprecision::detail::is_unsigned<SignedIntegralType>::value
246+
typename ::std::enable_if<( boost::multiprecision::detail::is_integral<SignedIntegralType>::value
247+
&& (!boost::multiprecision::detail::is_unsigned<SignedIntegralType>::value)
249248
&& (static_cast<int>(sizeof(SignedIntegralType) * 8u) <= cpp_df_qf_detail::ccmath::numeric_limits<float_type>::digits))>::type const* = nullptr>
250249
constexpr cpp_double_fp_backend(const SignedIntegralType& n)
251250
: data(static_cast<float_type>(n), static_cast<float_type>(0.0F)) { }
@@ -276,8 +275,8 @@ class cpp_double_fp_backend
276275
) { }
277276

278277
template <typename SignedIntegralType,
279-
typename ::std::enable_if<( boost::multiprecision::detail::is_integral<SignedIntegralType>::value
280-
&& !boost::multiprecision::detail::is_unsigned<SignedIntegralType>::value
278+
typename ::std::enable_if<( boost::multiprecision::detail::is_integral<SignedIntegralType>::value
279+
&& (!boost::multiprecision::detail::is_unsigned<SignedIntegralType>::value)
281280
&& (static_cast<int>(sizeof(SignedIntegralType) * 8u) > cpp_df_qf_detail::ccmath::numeric_limits<float_type>::digits))>::type const* = nullptr>
282281
constexpr cpp_double_fp_backend(SignedIntegralType n)
283282
: data
@@ -355,7 +354,7 @@ class cpp_double_fp_backend
355354
// TBD: Is there a faster or more simple hash method?
356355
// TBD: Is there any constexpr support for rudimentary hashing?
357356

358-
const auto str_to_hash = str(cpp_double_fp_backend::my_digits10, std::ios::scientific);
357+
const std::string str_to_hash { str(cpp_double_fp_backend::my_digits10, std::ios::scientific) };
359358

360359
auto result = static_cast<std::size_t>(UINT8_C(0));
361360

@@ -387,11 +386,11 @@ class cpp_double_fp_backend
387386
}
388387
else if (isinf_u)
389388
{
390-
data.first = -data.first;
389+
data.first = -data.first;
391390
}
392391
else
393392
{
394-
data.first = -data.first;
393+
data.first = -data.first;
395394

396395
if (data.second != 0) { data.second = -data.second; }
397396

@@ -405,13 +404,14 @@ class cpp_double_fp_backend
405404
constexpr const float_type& my_first () const noexcept { return data.first; }
406405
constexpr const float_type& my_second() const noexcept { return data.second; }
407406

408-
constexpr rep_type& rep () noexcept { return data; }
407+
constexpr rep_type& rep() noexcept { return data; }
409408

410-
constexpr const rep_type& rep () const noexcept { return data; }
409+
constexpr const rep_type& rep() const noexcept { return data; }
411410

412411
constexpr const rep_type& crep() const noexcept { return data; }
413412

414-
// Unary add/sub/mul/div.
413+
// Unary add/sub/mul/div follow in the upcoming paragraphs.
414+
415415
constexpr cpp_double_fp_backend& operator+=(const cpp_double_fp_backend& v)
416416
{
417417
const auto fpc_u = eval_fpclassify(*this);
@@ -527,12 +527,12 @@ class cpp_double_fp_backend
527527
const auto fpc_v = eval_fpclassify(v);
528528

529529
// Handle special cases like zero, inf and NaN.
530-
const bool isinf_u = (fpc_u == FP_INFINITE);
531-
const bool isinf_v = (fpc_v == FP_INFINITE);
532-
const bool isnan_u = (fpc_u == FP_NAN);
533-
const bool isnan_v = (fpc_v == FP_NAN);
534-
const bool iszero_u = (fpc_u == FP_ZERO);
535-
const bool iszero_v = (fpc_v == FP_ZERO);
530+
const bool isinf_u { fpc_u == FP_INFINITE };
531+
const bool isinf_v { fpc_v == FP_INFINITE };
532+
const bool isnan_u { fpc_u == FP_NAN };
533+
const bool isnan_v { fpc_v == FP_NAN };
534+
const bool iszero_u { fpc_u == FP_ZERO };
535+
const bool iszero_v { fpc_v == FP_ZERO };
536536

537537
if ((isnan_u || isnan_v) || (isinf_u && iszero_v) || (isinf_v && iszero_u))
538538
{
@@ -828,7 +828,12 @@ class cpp_double_fp_backend
828828
if (number_of_digits == 0)
829829
number_of_digits = cpp_double_fp_backend::my_digits10;
830830

831-
const std::string my_str = boost::multiprecision::detail::convert_to_string(*this, number_of_digits, format_flags);
831+
cpp_dec_float_read_write_type f_dec { 0 };
832+
833+
f_dec += data.second;
834+
f_dec += data.first;
835+
836+
const std::string my_str { f_dec.str(number_of_digits, format_flags) };
832837

833838
return my_str;
834839
}
@@ -935,6 +940,18 @@ class cpp_double_fp_backend
935940
private:
936941
rep_type data;
937942

943+
static constexpr auto cpp_dec_float_read_write_digits10 =
944+
static_cast<int>
945+
(
946+
static_cast<float>
947+
(
948+
static_cast<float>(my_digits) * 0.9F
949+
)
950+
);
951+
952+
using cpp_dec_float_read_write_type = boost::multiprecision::cpp_dec_float<static_cast<unsigned>(cpp_dec_float_read_write_digits10), std::int32_t, std::allocator<void>>;
953+
using cpp_dec_float_read_write_exp_type = typename cpp_dec_float_read_write_type::exponent_type;
954+
938955
bool rd_string(const char* pstr);
939956

940957
static constexpr rep_type two_sum(const float_type a, const float_type b)
@@ -982,19 +999,7 @@ bool cpp_double_fp_backend<FloatingPointType>::rd_string(const char* pstr)
982999

9831000
using local_double_fp_type = cpp_double_fp_backend<FloatingPointType>;
9841001

985-
constexpr auto local_cpp_dec_float_digits10 =
986-
static_cast<int>
987-
(
988-
static_cast<float>
989-
(
990-
static_cast<float>(local_double_fp_type::my_digits) * 0.9F
991-
)
992-
);
993-
994-
using local_cpp_dec_float_type = boost::multiprecision::cpp_dec_float<static_cast<unsigned>(local_cpp_dec_float_digits10), std::int32_t, std::allocator<void>>;
995-
using local_cpp_dec_float_exp_type = typename local_cpp_dec_float_type::exponent_type;
996-
997-
local_cpp_dec_float_type f_dec = pstr;
1002+
cpp_dec_float_read_write_type f_dec = pstr;
9981003

9991004
const auto fpc = eval_fpclassify(f_dec);
10001005

@@ -1006,7 +1011,7 @@ bool cpp_double_fp_backend<FloatingPointType>::rd_string(const char* pstr)
10061011
}
10071012
else
10081013
{
1009-
local_cpp_dec_float_type dummy_frexp { };
1014+
cpp_dec_float_read_write_type dummy_frexp { };
10101015
auto e2_from_f_dec = int { };
10111016
eval_frexp(dummy_frexp, f_dec, &e2_from_f_dec);
10121017

@@ -1015,7 +1020,7 @@ bool cpp_double_fp_backend<FloatingPointType>::rd_string(const char* pstr)
10151020
// TBD: A detailed, clear comparison (or something close to a comparison)
10161021
// is still needed for input values having (e2_from_f_dec == my_min_exponent).
10171022
(fpc == FP_ZERO)
1018-
|| (e2_from_f_dec < static_cast<local_cpp_dec_float_exp_type>(local_double_fp_type::my_min_exponent))
1023+
|| (e2_from_f_dec < static_cast<cpp_dec_float_read_write_exp_type>(local_double_fp_type::my_min_exponent))
10191024
);
10201025

10211026
if (is_definitely_zero)
@@ -1027,7 +1032,7 @@ bool cpp_double_fp_backend<FloatingPointType>::rd_string(const char* pstr)
10271032
{
10281033
// TBD: A detailed, clear comparison (or something close to a comparison)
10291034
// is still needed for input values having (e2_from_f_dec == my_max_exponent).
1030-
const auto is_definitely_inf = (e2_from_f_dec > static_cast<local_cpp_dec_float_exp_type>(local_double_fp_type::my_max_exponent));
1035+
const auto is_definitely_inf = (e2_from_f_dec > static_cast<cpp_dec_float_read_write_exp_type>(local_double_fp_type::my_max_exponent));
10311036

10321037
if (is_definitely_inf)
10331038
{
@@ -1063,18 +1068,18 @@ bool cpp_double_fp_backend<FloatingPointType>::rd_string(const char* pstr)
10631068

10641069
if (has_pow2_scaling_for_small_input)
10651070
{
1066-
f_dec *= local_cpp_dec_float_type::pow2(static_cast<long long>(pow2_scaling_for_small_input));
1071+
f_dec *= cpp_dec_float_read_write_type::pow2(static_cast<long long>(pow2_scaling_for_small_input));
10671072
}
10681073

10691074
for(auto i = static_cast<unsigned>(UINT8_C(0));
10701075
i < dig_lim;
10711076
i = static_cast<unsigned>(i + static_cast<unsigned>(cpp_df_qf_detail::ccmath::numeric_limits<local_builtin_float_type>::digits)))
10721077
{
1073-
local_cpp_dec_float_type f_dec_abs { };
1078+
cpp_dec_float_read_write_type f_dec_abs { };
10741079

10751080
eval_fabs(f_dec_abs, f_dec);
10761081

1077-
if (f_dec_abs.compare((local_cpp_dec_float_type::min)()) <= 0)
1082+
if (f_dec_abs.compare((cpp_dec_float_read_write_type::min)()) <= 0)
10781083
{
10791084
break;
10801085
}
@@ -1212,7 +1217,7 @@ constexpr cpp_double_fp_backend<FloatingPointType> operator/(const cpp_double_fp
12121217
// Input/Output Streaming
12131218
template <typename FloatingPointType, typename char_type, typename traits_type>
12141219
::std::basic_ostream<char_type, traits_type>&
1215-
operator<<(std::basic_ostream<char_type, traits_type>& os, const cpp_double_fp_backend<FloatingPointType>& f)
1220+
operator<<(::std::basic_ostream<char_type, traits_type>& os, const cpp_double_fp_backend<FloatingPointType>& f)
12161221
{
12171222
const auto str_result = f.str(os.precision(), os.flags());
12181223

@@ -1221,7 +1226,7 @@ operator<<(std::basic_ostream<char_type, traits_type>& os, const cpp_double_fp_b
12211226

12221227
template <typename FloatingPointType, typename char_type, typename traits_type>
12231228
::std::basic_istream<char_type, traits_type>&
1224-
operator>>(std::basic_istream<char_type, traits_type>& is, cpp_double_fp_backend<FloatingPointType>& f)
1229+
operator>>(::std::basic_istream<char_type, traits_type>& is, cpp_double_fp_backend<FloatingPointType>& f)
12251230
{
12261231
std::string input_str;
12271232

@@ -1859,7 +1864,7 @@ constexpr void eval_log(cpp_double_fp_backend<FloatingPointType>& result, const
18591864
else if (eval_lt(x, double_float_type(1)))
18601865
{
18611866
// TBD: Optimize check with 1.
1862-
// TBD: optimize inversion and negation.
1867+
// TBD: Optimize inversion and negation.
18631868

18641869
double_float_type x_inv;
18651870
eval_divide(x_inv, double_float_type(1), x);
@@ -1889,7 +1894,7 @@ constexpr void eval_log(cpp_double_fp_backend<FloatingPointType>& result, const
18891894
// Do one single step of Newton-Raphson iteration.
18901895
result = s + ((x2 - E) / E);
18911896

1892-
double_float_type xn2(n2);
1897+
double_float_type xn2 { n2 };
18931898

18941899
eval_multiply(xn2, cpp_df_qf_detail::constant_df_ln_two<typename double_float_type::float_type>());
18951900

@@ -2304,8 +2309,4 @@ struct precision<boost::multiprecision::number<boost::multiprecision::cpp_double
23042309
} } } // namespace boost::math::policies
23052310
#endif
23062311

2307-
#if (defined(_MSC_VER) && (_MSC_VER <= 1900))
2308-
#pragma warning(pop)
2309-
#endif
2310-
23112312
#endif // BOOST_MP_CPP_DOUBLE_FP_2021_06_05_HPP

0 commit comments

Comments
 (0)