Skip to content

Commit

Permalink
Merge pull request #756 from cppalliance/ldbl_conv
Browse files Browse the repository at this point in the history
Enable 80 and 128 bit long double conversions
  • Loading branch information
mborland authored Oct 7, 2024
2 parents f6675a9 + 833b6e3 commit 1b5d18a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
3 changes: 1 addition & 2 deletions include/boost/decimal/decimal64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<long double>(to_float<decimal64, double>(*this));
return to_float<decimal64, long double>(*this);
}

#ifdef BOOST_DECIMAL_HAS_FLOAT16
Expand Down
3 changes: 1 addition & 2 deletions include/boost/decimal/decimal64_fast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,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<long double>(to_float<decimal64_fast, double>(*this));
return to_float<decimal64_fast, long double>(*this);
}

#ifdef BOOST_DECIMAL_HAS_FLOAT16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ constexpr auto fast_path(const std::int64_t q, const Unsigned_Integer &w, bool n
#endif

template <typename Unsigned_Integer>
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
Expand Down
3 changes: 1 addition & 2 deletions include/boost/decimal/detail/to_float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ BOOST_DECIMAL_CXX20_CONSTEXPR auto to_float(Decimal val) noexcept
#if BOOST_DECIMAL_LDBL_BITS == 64
result = static_cast<TargetType>(detail::fast_float::compute_float64(exp, new_sig, val.isneg(), success));
#else
result = static_cast<TargetType>(detail::fast_float::compute_float80(exp, new_sig, val.isneg(), success));
result = static_cast<TargetType>(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))
{
Expand Down

0 comments on commit 1b5d18a

Please sign in to comment.