Skip to content

Commit a1956a6

Browse files
authored
Merge pull request #340 from cppalliance/128
2 parents 270204a + 549668f commit a1956a6

File tree

6 files changed

+71
-2
lines changed

6 files changed

+71
-2
lines changed

include/boost/decimal/decimal128.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ class decimal128 final
249249
explicit constexpr operator std::int16_t() const noexcept;
250250
explicit constexpr operator std::uint16_t() const noexcept;
251251

252+
#ifdef BOOST_DECIMAL_HAS_INT128
253+
explicit constexpr operator detail::int128_t() const noexcept;
254+
explicit constexpr operator detail::uint128_t() const noexcept;
255+
#endif
256+
252257
// 3.2.6 Conversion to floating-point type
253258
explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator float() const noexcept;
254259
explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator double() const noexcept;
@@ -917,6 +922,20 @@ constexpr decimal128::operator std::uint16_t() const noexcept
917922
return to_integral_128<decimal128, std::uint16_t>(*this);
918923
}
919924

925+
#ifdef BOOST_DECIMAL_HAS_INT128
926+
927+
constexpr decimal128::operator detail::int128_t() const noexcept
928+
{
929+
return to_integral_128<decimal128, detail::int128_t>(*this);
930+
}
931+
932+
constexpr decimal128::operator detail::uint128_t() const noexcept
933+
{
934+
return to_integral_128<decimal128, detail::uint128_t>(*this);
935+
}
936+
937+
#endif //BOOST_DECIMAL_HAS_INT128
938+
920939
BOOST_DECIMAL_CXX20_CONSTEXPR decimal128::operator float() const noexcept
921940
{
922941
return to_float<decimal128, float>(*this);

include/boost/decimal/decimal32.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ class decimal32 final // NOLINT(cppcoreguidelines-special-member-functions,hicpp
231231
explicit constexpr operator std::int16_t() const noexcept;
232232
explicit constexpr operator std::uint16_t() const noexcept;
233233

234+
#ifdef BOOST_DECIMAL_HAS_INT128
235+
explicit constexpr operator detail::int128_t() const noexcept;
236+
explicit constexpr operator detail::uint128_t() const noexcept;
237+
#endif
238+
234239
template <typename Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool> = true>
235240
explicit constexpr operator Decimal() const noexcept;
236241

@@ -1633,6 +1638,20 @@ constexpr decimal32::operator std::uint16_t() const noexcept
16331638
return to_integral<decimal32, std::uint16_t>(*this);
16341639
}
16351640

1641+
#ifdef BOOST_DECIMAL_HAS_INT128
1642+
1643+
constexpr decimal32::operator detail::int128_t() const noexcept
1644+
{
1645+
return to_integral<decimal32, detail::int128_t>(*this);
1646+
}
1647+
1648+
constexpr decimal32::operator detail::uint128_t() const noexcept
1649+
{
1650+
return to_integral<decimal32, detail::uint128_t>(*this);
1651+
}
1652+
1653+
#endif
1654+
16361655
template <typename Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool>>
16371656
constexpr decimal32::operator Decimal() const noexcept
16381657
{

include/boost/decimal/decimal64.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ class decimal64 final
236236
explicit constexpr operator std::int16_t() const noexcept;
237237
explicit constexpr operator std::uint16_t() const noexcept;
238238

239+
#ifdef BOOST_DECIMAL_HAS_INT128
240+
explicit constexpr operator detail::int128_t() const noexcept;
241+
explicit constexpr operator detail::uint128_t() const noexcept;
242+
#endif
243+
244+
239245
template <typename Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool> = true>
240246
explicit constexpr operator Decimal() const noexcept;
241247

@@ -807,6 +813,21 @@ constexpr decimal64::operator std::uint16_t() const noexcept
807813
return to_integral<decimal64, std::uint16_t>(*this);
808814
}
809815

816+
#ifdef BOOST_DECIMAL_HAS_INT128
817+
818+
constexpr decimal64::operator detail::int128_t() const noexcept
819+
{
820+
return to_integral<decimal64, detail::int128_t>(*this);
821+
}
822+
823+
constexpr decimal64::operator detail::uint128_t() const noexcept
824+
{
825+
return to_integral<decimal64, detail::uint128_t>(*this);
826+
}
827+
828+
#endif
829+
830+
810831
template <typename Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool>>
811832
constexpr decimal64::operator Decimal() const noexcept
812833
{

include/boost/decimal/detail/emulated128.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ struct uint128
161161
explicit constexpr operator bool() const noexcept { return high || low; }
162162

163163
#ifdef BOOST_DECIMAL_HAS_INT128
164-
explicit constexpr operator boost::int128_type() const noexcept { return (static_cast<boost::int128_type>(high) << 64) + low; }
165-
explicit constexpr operator boost::uint128_type() const noexcept { return (static_cast<boost::uint128_type>(high) << 64) + low; }
164+
explicit constexpr operator int128_t() noexcept { return (static_cast<int128_t>(high) << 64) + low; }
165+
explicit constexpr operator uint128_t() const noexcept { return (static_cast<uint128_t>(high) << 64) + low; }
166166
#endif
167167

168168
#ifdef BOOST_DECIMAL_HAS_FLOAT128

test/roundtrip_decimal32.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ int main()
262262
test_roundtrip_conversion_integer<std::int64_t>(-9'999'999, 9'999'999);
263263
test_roundtrip_conversion_integer<std::uint64_t>(0, 9'999'999);
264264

265+
#if defined(BOOST_DECIMAL_HAS_INT128) && !defined(__STRICT_ANSI__)
266+
test_roundtrip_conversion_integer<detail::int128_t>(-9'999'999, 9'999'999);
267+
test_roundtrip_conversion_integer<detail::uint128_t>(0, 9'999'999);
268+
#endif
269+
265270
test_conversion_to_float<float>();
266271
test_conversion_to_float<double>();
267272
test_conversion_to_float<long double>();

test/roundtrip_decimal64.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ int main()
278278
test_roundtrip_conversion_integer<std::int64_t>(-9'999'999, 9'999'999);
279279
test_roundtrip_conversion_integer<std::uint64_t>(0, 9'999'999);
280280

281+
#if defined(BOOST_DECIMAL_HAS_INT128) && !defined(__STRICT_ANSI__)
282+
test_roundtrip_conversion_integer<detail::int128_t>(-9'999'999, 9'999'999);
283+
test_roundtrip_conversion_integer<detail::uint128_t>(0, 9'999'999);
284+
#endif
285+
281286
test_conversion_from_float<float>();
282287
test_conversion_from_float<double>();
283288
test_conversion_from_float<long double>();

0 commit comments

Comments
 (0)