Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable 80 and 128 bit long double conversions #756

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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<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
Loading