From df650edeaf75b7c16426a6a3ee97d0c64738a80d Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 7 Oct 2024 11:18:55 -0400 Subject: [PATCH 1/2] Refactor computation of 80 and 128 bit ldbls --- .../boost/decimal/detail/fast_float/compute_float80_128.hpp | 4 ++-- include/boost/decimal/detail/to_float.hpp | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/boost/decimal/detail/fast_float/compute_float80_128.hpp b/include/boost/decimal/detail/fast_float/compute_float80_128.hpp index 8fd6e8831..af60dfe04 100644 --- a/include/boost/decimal/detail/fast_float/compute_float80_128.hpp +++ b/include/boost/decimal/detail/fast_float/compute_float80_128.hpp @@ -69,8 +69,8 @@ constexpr auto fast_path(const std::int64_t q, const Unsigned_Integer &w, bool n #endif template -constexpr auto compute_float80(std::int64_t q, const Unsigned_Integer &w, - const bool negative, bool &success) noexcept -> long double +constexpr auto compute_float80_128(std::int64_t q, const Unsigned_Integer &w, + const bool negative, bool &success) noexcept -> long double { // GLIBC uses 2^-16444 but MPFR uses 2^-16445 as the smallest subnormal value for 80 bit // 39 is the max number of digits in an uint128_t diff --git a/include/boost/decimal/detail/to_float.hpp b/include/boost/decimal/detail/to_float.hpp index a93e15b8d..93f7d9757 100644 --- a/include/boost/decimal/detail/to_float.hpp +++ b/include/boost/decimal/detail/to_float.hpp @@ -72,10 +72,9 @@ BOOST_DECIMAL_CXX20_CONSTEXPR auto to_float(Decimal val) noexcept #if BOOST_DECIMAL_LDBL_BITS == 64 result = static_cast(detail::fast_float::compute_float64(exp, new_sig, val.isneg(), success)); #else - result = static_cast(detail::fast_float::compute_float80(exp, new_sig, val.isneg(), success)); + result = static_cast(detail::fast_float::compute_float80_128(exp, new_sig, val.isneg(), success)); #endif } - // TODO(mborland): Add conversion for __float128 and 128 bit long doubles if (BOOST_DECIMAL_UNLIKELY(!success)) { From 833b6e3ce081e20d9834901c789a0fa28e05e4e6 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 7 Oct 2024 11:19:10 -0400 Subject: [PATCH 2/2] Enable conversions to 80 and 128 bit long doubles --- include/boost/decimal/decimal64.hpp | 3 +-- include/boost/decimal/decimal64_fast.hpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/boost/decimal/decimal64.hpp b/include/boost/decimal/decimal64.hpp index 59e5e64df..52a8af3bf 100644 --- a/include/boost/decimal/decimal64.hpp +++ b/include/boost/decimal/decimal64.hpp @@ -970,8 +970,7 @@ BOOST_DECIMAL_CXX20_CONSTEXPR decimal64::operator double() const noexcept BOOST_DECIMAL_CXX20_CONSTEXPR decimal64::operator long double() const noexcept { - // TODO(mborland): Don't have an exact way of converting to various long doubles - return static_cast(to_float(*this)); + return to_float(*this); } #ifdef BOOST_DECIMAL_HAS_FLOAT16 diff --git a/include/boost/decimal/decimal64_fast.hpp b/include/boost/decimal/decimal64_fast.hpp index 5a30f1a65..4011dec9e 100644 --- a/include/boost/decimal/decimal64_fast.hpp +++ b/include/boost/decimal/decimal64_fast.hpp @@ -885,8 +885,7 @@ BOOST_DECIMAL_CXX20_CONSTEXPR decimal64_fast::operator double() const noexcept BOOST_DECIMAL_CXX20_CONSTEXPR decimal64_fast::operator long double() const noexcept { - // TODO(mborland): Don't have an exact way of converting to various long doubles - return static_cast(to_float(*this)); + return to_float(*this); } #ifdef BOOST_DECIMAL_HAS_FLOAT16