Skip to content

Commit 63c121f

Browse files
committed
Simplify and document d128f bid conversions
1 parent ec1059a commit 63c121f

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

doc/decimal/conversions.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ constexpr decimal128 from_bid_d128(unsigned __int128 bits) noexcept;
5656
5757
#endif // BOOST_DECIMAL_HAS_INT128
5858
59+
constexpr detail::uint128 to_bid_d128f(decimal128_fast val) noexcept;
60+
61+
constexpr decimal128 from_bid_d128f(detail::uint128 bits) noexcept;
62+
63+
#ifdef BOOST_DECIMAL_HAS_INT128
64+
65+
constexpr decimal128 from_bid_d128f(unsigned __int128 bits) noexcept;
66+
67+
#endif // BOOST_DECIMAL_HAS_INT128
68+
5969
template <typename T>
6070
constexpr auto to_bid(T val) noexcept;
6171

include/boost/decimal/bid_conversion.hpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,85 +83,93 @@ constexpr auto from_bits_d128(detail::uint128_t bits) noexcept -> decimal128
8383
}
8484
#endif
8585

86-
BOOST_DECIMAL_CXX20_CONSTEXPR auto to_bid_d128f(decimal128_fast val) noexcept -> detail::uint128
86+
constexpr auto to_bid_d128f(decimal128_fast val) noexcept -> detail::uint128
8787
{
8888
const decimal128 compliant_val {val};
89-
const auto bits {detail::bit_cast<detail::uint128>(compliant_val)};
90-
return bits;
89+
return to_bid_d128(compliant_val);
9190
}
9291

93-
BOOST_DECIMAL_CXX20_CONSTEXPR auto from_bid_d128f(detail::uint128 bits) noexcept -> decimal128_fast
92+
constexpr auto from_bid_d128f(detail::uint128 bits) noexcept -> decimal128_fast
9493
{
95-
const auto compliant_val {detail::bit_cast<decimal128>(bits)};
94+
const auto compliant_val {from_bid_d128(bits)};
9695
const decimal128_fast val {compliant_val};
9796
return val;
9897
}
9998

100-
BOOST_DECIMAL_CXX20_CONSTEXPR auto to_bid(decimal32 val) noexcept -> std::uint32_t
99+
#ifdef BOOST_DECIMAL_HAS_INT128
100+
constexpr auto from_bid_d128f(detail::uint128_t bits) noexcept -> decimal128_fast
101+
{
102+
const auto compliant_val {from_bid_d128(bits)};
103+
const decimal128_fast val {compliant_val};
104+
return val;
105+
}
106+
#endif
107+
108+
constexpr auto to_bid(decimal32 val) noexcept -> std::uint32_t
101109
{
102110
return to_bid_d32(val);
103111
}
104112

105-
BOOST_DECIMAL_CXX20_CONSTEXPR auto to_bid(decimal32_fast val) noexcept -> std::uint32_t
113+
constexpr auto to_bid(decimal32_fast val) noexcept -> std::uint32_t
106114
{
107115
return to_bid_d32f(val);
108116
}
109117

110-
BOOST_DECIMAL_CXX20_CONSTEXPR auto to_bid(decimal64 val) noexcept -> std::uint64_t
118+
constexpr auto to_bid(decimal64 val) noexcept -> std::uint64_t
111119
{
112120
return to_bid_d64(val);
113121
}
114122

115-
BOOST_DECIMAL_CXX20_CONSTEXPR auto to_bid(decimal64_fast val) noexcept -> std::uint64_t
123+
constexpr auto to_bid(decimal64_fast val) noexcept -> std::uint64_t
116124
{
117125
return to_bid_d64f(val);
118126
}
119127

120-
BOOST_DECIMAL_CXX20_CONSTEXPR auto to_bid(decimal128 val) noexcept -> detail::uint128
128+
constexpr auto to_bid(decimal128 val) noexcept -> detail::uint128
121129
{
122130
return to_bid_d128(val);
123131
}
124132

125-
BOOST_DECIMAL_CXX20_CONSTEXPR auto to_bid(decimal128_fast val) noexcept -> detail::uint128
133+
constexpr auto to_bid(decimal128_fast val) noexcept -> detail::uint128
126134
{
127135
return to_bid_d128f(val);
128136
}
129137

130138
template <typename T = decimal32_fast>
131-
BOOST_DECIMAL_CXX20_CONSTEXPR auto from_bid(std::uint32_t bits) noexcept
139+
constexpr auto from_bid(std::uint32_t bits) noexcept
132140
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T)
133141
{
134142
return from_bid_d32f(bits);
135143
}
136144

137145
template <>
138-
BOOST_DECIMAL_CXX20_CONSTEXPR auto from_bid<decimal32>(std::uint32_t bits) noexcept -> decimal32
146+
constexpr auto from_bid<decimal32>(std::uint32_t bits) noexcept -> decimal32
139147
{
140148
return from_bid_d32(bits);
141149
}
142150

143151
template <typename T = decimal64_fast>
144-
BOOST_DECIMAL_CXX20_CONSTEXPR auto from_bid(std::uint64_t bits) noexcept
152+
constexpr auto from_bid(std::uint64_t bits) noexcept
145153
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T)
146154
{
147155
return from_bid_d64f(bits);
148156
}
149157

150158
template <>
151-
BOOST_DECIMAL_CXX20_CONSTEXPR auto from_bid<decimal64>(std::uint64_t bits) noexcept -> decimal64
159+
constexpr auto from_bid<decimal64>(std::uint64_t bits) noexcept -> decimal64
152160
{
153161
return from_bid_d64(bits);
154162
}
155163

156164
template <typename T = decimal128_fast>
157-
BOOST_DECIMAL_CXX20_CONSTEXPR auto from_bid(detail::uint128 bits) noexcept
165+
constexpr auto from_bid(detail::uint128 bits) noexcept
158166
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T)
159167
{
160168
return from_bid_d128f(bits);
161169
}
162170

163171
template <>
164-
BOOST_DECIMAL_CXX20_CONSTEXPR auto from_bid<decimal128>(detail::uint128 bits) noexcept -> decimal128
172+
constexpr auto from_bid<decimal128>(detail::uint128 bits) noexcept -> decimal128
165173
{
166174
return from_bid_d128(bits);
167175
}

0 commit comments

Comments
 (0)