Skip to content

Commit 558de21

Browse files
committed
Add conversion to other floating point type
1 parent e3327a8 commit 558de21

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

include/boost/decimal/decimal32_fast.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class decimal32_fast final
7171
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
7272
friend constexpr auto frexp10(T num, int* expptr) noexcept -> typename T::significand_type;
7373

74+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetType, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal>
75+
friend constexpr auto to_decimal(Decimal val) noexcept -> TargetType;
76+
7477
public:
7578
constexpr decimal32_fast() noexcept : significand_{}, exponent_{}, sign_ {} {}
7679

@@ -143,6 +146,9 @@ class decimal32_fast final
143146
explicit constexpr operator detail::uint128_t() const noexcept;
144147
#endif
145148

149+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool> = true>
150+
explicit constexpr operator Decimal() const noexcept;
151+
146152
friend constexpr auto direct_init(std::uint_fast32_t significand, std::uint_fast8_t exponent, bool sign) noexcept -> decimal32_fast;
147153
};
148154

@@ -644,6 +650,12 @@ constexpr decimal32_fast::operator detail::uint128_t() const noexcept
644650

645651
#endif
646652

653+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool>>
654+
constexpr decimal32_fast::operator Decimal() const noexcept
655+
{
656+
return to_decimal<Decimal>(*this);
657+
}
658+
647659
} // namespace decimal
648660
} // namespace boost
649661

0 commit comments

Comments
 (0)