From 76224e2466445c7d98fe5a479e6dca6f56aac123 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Mon, 21 Jul 2025 15:00:23 +0200 Subject: [PATCH] Fix a typo and get even more cover dec-float --- example/exercise_threading_log_agm.cpp | 2 +- .../boost/multiprecision/cpp_dec_float.hpp | 27 +++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/example/exercise_threading_log_agm.cpp b/example/exercise_threading_log_agm.cpp index 10a41f63..0a9625b5 100644 --- a/example/exercise_threading_log_agm.cpp +++ b/example/exercise_threading_log_agm.cpp @@ -71,7 +71,7 @@ //#define BOOST_MP_EXERCISE_THREADING_BACKEND_TYPE BOOST_MP_EXERCISE_THREADING_BACKEND_MPFR_FLOAT #endif -constexpr unsigned local_mp_digits { 101U }; +constexpr unsigned local_mp_digits { 301U }; #if (BOOST_MP_EXERCISE_THREADING_BACKEND_TYPE == BOOST_MP_EXERCISE_THREADING_BACKEND_CPP_DEC_FLOAT) #include diff --git a/include/boost/multiprecision/cpp_dec_float.hpp b/include/boost/multiprecision/cpp_dec_float.hpp index e854af78..e9ae39f5 100644 --- a/include/boost/multiprecision/cpp_dec_float.hpp +++ b/include/boost/multiprecision/cpp_dec_float.hpp @@ -1246,7 +1246,11 @@ cpp_dec_float& cpp_dec_float(1.0 / dd, -ne)); // Compute the inverse of *this. Quadratically convergent Newton-Raphson iteration @@ -1316,7 +1320,10 @@ cpp_dec_float& cpp_dec_float(sqd, static_cast(ne / static_cast(2))); @@ -1535,7 +1542,8 @@ void cpp_dec_float::extract_parts(double& man mantissa /= p10; // Extract the rest of the mantissa piecewise from the limbs. - // This loop does not round. + // This loop does not round. For finite values, the absolute + // value of the mantissa is scaled and between 1 and 10. auto itr_data = data.cbegin() + static_cast(UINT8_C(1)); @@ -2423,11 +2431,14 @@ cpp_dec_float::cpp_dec_float(const double man { exponent_type exp10_val { exp10 }; - while (d_mant > 10.0) - { - d_mant /= 10.0; - ++exp10_val; - } + // This subroutine is used after a call to extract_parts(). + // The corresponding scaling loop for (d_mant > 10.0) is not + // needed here since extract_parts() returns a mantissa value + // between 1 and 10. The loop for (d_mant < 1.0) is needed + // since the initial guess of the square root in tghe subroutine + // calculate_root() might have been divided by 10 in order + // to obtain an exponent value that is a multiple of 2. + while (d_mant < 1.0) { d_mant *= 10.0;