diff --git a/include/boost/decimal/detail/cmath/cbrt.hpp b/include/boost/decimal/detail/cmath/cbrt.hpp index 884ac8ea3..bc983480a 100644 --- a/include/boost/decimal/detail/cmath/cbrt.hpp +++ b/include/boost/decimal/detail/cmath/cbrt.hpp @@ -61,7 +61,7 @@ constexpr auto cbrt_impl(const T x) noexcept remove_trailing_zeros(gn) }; - const bool is_pure { static_cast(zeros_removal.trimmed_number) == 1U }; + const bool is_pure { zeros_removal.trimmed_number == 1U }; if(is_pure) { diff --git a/include/boost/decimal/detail/cmath/log10.hpp b/include/boost/decimal/detail/cmath/log10.hpp index 3b3b32bec..49f3a95f4 100644 --- a/include/boost/decimal/detail/cmath/log10.hpp +++ b/include/boost/decimal/detail/cmath/log10.hpp @@ -63,7 +63,7 @@ constexpr auto log10_impl(const T x) noexcept remove_trailing_zeros(gn) }; - const bool is_pure { static_cast(zeros_removal.trimmed_number) == 1U }; + const bool is_pure { zeros_removal.trimmed_number == 1U }; if(is_pure) { diff --git a/include/boost/decimal/detail/cmath/sqrt.hpp b/include/boost/decimal/detail/cmath/sqrt.hpp index e68dcb36d..3e4b5942c 100644 --- a/include/boost/decimal/detail/cmath/sqrt.hpp +++ b/include/boost/decimal/detail/cmath/sqrt.hpp @@ -61,7 +61,7 @@ constexpr auto sqrt_impl(const T x) noexcept remove_trailing_zeros(gn) }; - const bool is_pure { static_cast(zeros_removal.trimmed_number) == 1U }; + const bool is_pure { zeros_removal.trimmed_number == 1U }; constexpr T one { 1 }; diff --git a/include/boost/decimal/detail/power_tables.hpp b/include/boost/decimal/detail/power_tables.hpp index 3e0e9f83c..327d5cd3d 100644 --- a/include/boost/decimal/detail/power_tables.hpp +++ b/include/boost/decimal/detail/power_tables.hpp @@ -35,53 +35,52 @@ BOOST_DECIMAL_INLINE_CONSTEXPR_VARIABLE std::uint64_t powers_of_10[20] = UINT64_C(10000000000000000000) }; -BOOST_DECIMAL_INLINE_CONSTEXPR_VARIABLE boost::int128::uint128_t BOOST_DECIMAL_DETAIL_INT128_pow10[] = +BOOST_DECIMAL_INLINE_CONSTEXPR_VARIABLE boost::int128::uint128_t BOOST_DECIMAL_DETAIL_INT128_pow10[39] = { - boost::int128::uint128_t {UINT64_C(0), UINT64_C(1)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(10)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(100)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(1000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(10000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(100000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(1000000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(10000000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(100000000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(1000000000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(10000000000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(100000000000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(1000000000000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(10000000000000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(100000000000000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(1000000000000000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(10000000000000000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(100000000000000000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(1000000000000000000)}, - boost::int128::uint128_t {UINT64_C(0), UINT64_C(10000000000000000000)}, - boost::int128::uint128_t {UINT64_C(5), UINT64_C(7766279631452241920)}, - boost::int128::uint128_t {UINT64_C(54), UINT64_C(3875820019684212736)}, - boost::int128::uint128_t {UINT64_C(542), UINT64_C(1864712049423024128)}, - boost::int128::uint128_t {UINT64_C(5421), UINT64_C(200376420520689664)}, - boost::int128::uint128_t {UINT64_C(54210), UINT64_C(2003764205206896640)}, - boost::int128::uint128_t {UINT64_C(542101), UINT64_C(1590897978359414784)}, - boost::int128::uint128_t {UINT64_C(5421010), UINT64_C(15908979783594147840)}, - boost::int128::uint128_t {UINT64_C(54210108), UINT64_C(11515845246265065472)}, - boost::int128::uint128_t {UINT64_C(542101086), UINT64_C(4477988020393345024)}, - boost::int128::uint128_t {UINT64_C(5421010862), UINT64_C(7886392056514347008)}, - boost::int128::uint128_t {UINT64_C(54210108624), UINT64_C(5076944270305263616)}, - boost::int128::uint128_t {UINT64_C(542101086242), UINT64_C(13875954555633532928)}, - boost::int128::uint128_t {UINT64_C(5421010862427), UINT64_C(9632337040368467968)}, - boost::int128::uint128_t {UINT64_C(54210108624275), UINT64_C(4089650035136921600)}, - boost::int128::uint128_t {UINT64_C(542101086242752), UINT64_C(4003012203950112768)}, - boost::int128::uint128_t {UINT64_C(5421010862427522), UINT64_C(3136633892082024448)}, - boost::int128::uint128_t {UINT64_C(54210108624275221), UINT64_C(12919594847110692864)}, - boost::int128::uint128_t {UINT64_C(542101086242752217), UINT64_C(68739955140067328)}, - boost::int128::uint128_t {UINT64_C(5421010862427522170), UINT64_C(687399551400673280)}, - boost::int128::uint128_t {UINT64_C(17316620476856118468), UINT64_C(6873995514006732800)}, + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(1), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(10), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(100), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(1000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(10000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(100000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(1000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(10000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(100000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(1000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(10000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(100000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(1000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(10000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(100000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(1000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(10000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(100000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(1000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(10000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(100000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(1000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(10000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(100000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(1000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(10000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(100000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(1000000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(10000000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(100000000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(1000000000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(10000000000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(100000000000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(1000000000000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(10000000000000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(100000000000000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(1000000000000000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(10000000000000000000000000000000000000), + BOOST_DECIMAL_DETAIL_INT128_UINT128_C(100000000000000000000000000000000000000) }; #ifdef BOOST_DECIMAL_HAS_INT128 -BOOST_DECIMAL_INLINE_CONSTEXPR_VARIABLE detail::builtin_uint128_t builtin_128_pow10[] = { +BOOST_DECIMAL_INLINE_CONSTEXPR_VARIABLE detail::builtin_uint128_t builtin_128_pow10[39] = { detail::builtin_uint128_t(1), detail::builtin_uint128_t(10), detail::builtin_uint128_t(100), @@ -121,92 +120,88 @@ BOOST_DECIMAL_INLINE_CONSTEXPR_VARIABLE detail::builtin_uint128_t builtin_128_po detail::builtin_uint128_t(10000000000000000000ULL) * detail::builtin_uint128_t(100000000000000000), detail::builtin_uint128_t(10000000000000000000ULL) * detail::builtin_uint128_t(1000000000000000000), detail::builtin_uint128_t(10000000000000000000ULL) * detail::builtin_uint128_t(10000000000000000000ULL), - detail::builtin_uint128_t(10000000000000000000ULL) * detail::builtin_uint128_t(10000000000000000000ULL) * detail::builtin_uint128_t(10ULL), }; -static_assert(sizeof(builtin_128_pow10) == sizeof(boost::decimal::detail::builtin_uint128_t) * 40, "Should have 10^0 to 10^39"); - #endif -BOOST_DECIMAL_INLINE_CONSTEXPR_VARIABLE u256 u256_pow_10[] = { - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(1)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(10)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(100)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(1000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(10000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(100000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(1000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(10000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(100000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(1000000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(10000000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(100000000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(1000000000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(10000000000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(100000000000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(1000000000000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(10000000000000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(100000000000000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(1000000000000000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(0), UINT64_C(10000000000000000000)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(5), UINT64_C(7766279631452241920)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(54), UINT64_C(3875820019684212736)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(542), UINT64_C(1864712049423024128)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(5421), UINT64_C(200376420520689664)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(54210), UINT64_C(2003764205206896640)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(542101), UINT64_C(1590897978359414784)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(5421010), UINT64_C(15908979783594147840)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(54210108), UINT64_C(11515845246265065472)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(542101086), UINT64_C(4477988020393345024)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(5421010862), UINT64_C(7886392056514347008)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(54210108624), UINT64_C(5076944270305263616)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(542101086242), UINT64_C(13875954555633532928)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(5421010862427), UINT64_C(9632337040368467968)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(54210108624275), UINT64_C(4089650035136921600)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(542101086242752), UINT64_C(4003012203950112768)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(5421010862427522), UINT64_C(3136633892082024448)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(54210108624275221), UINT64_C(12919594847110692864)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(542101086242752217), UINT64_C(68739955140067328)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(0)}, boost::int128::uint128_t{UINT64_C(5421010862427522170), UINT64_C(687399551400673280)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(2)}, boost::int128::uint128_t{UINT64_C(17316620476856118468), UINT64_C(6873995514006732800)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(29)}, boost::int128::uint128_t{UINT64_C(7145508105175220139), UINT64_C(13399722918938673152)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(293)}, boost::int128::uint128_t{UINT64_C(16114848830623546549), UINT64_C(4870020673419870208)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(2938)}, boost::int128::uint128_t{UINT64_C(13574535716559052564), UINT64_C(11806718586779598848)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(29387)}, boost::int128::uint128_t{UINT64_C(6618148649623664334), UINT64_C(7386721425538678784)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(293873)}, boost::int128::uint128_t{UINT64_C(10841254275107988496), UINT64_C(80237960548581376)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(2938735)}, boost::int128::uint128_t{UINT64_C(16178822382532126880), UINT64_C(802379605485813760)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(29387358)}, boost::int128::uint128_t{UINT64_C(14214271235644855872), UINT64_C(8023796054858137600)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(293873587)}, boost::int128::uint128_t{UINT64_C(13015503840481697412), UINT64_C(6450984253743169536)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(2938735877)}, boost::int128::uint128_t{UINT64_C(1027829888850112811), UINT64_C(9169610316303040512)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(29387358770)}, boost::int128::uint128_t{UINT64_C(10278298888501128114), UINT64_C(17909126868192198656)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(293873587705)}, boost::int128::uint128_t{UINT64_C(10549268516463523069), UINT64_C(13070572018536022016)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(2938735877055)}, boost::int128::uint128_t{UINT64_C(13258964796087472617), UINT64_C(1578511669393358848)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(29387358770557)}, boost::int128::uint128_t{UINT64_C(3462439444907864858), UINT64_C(15785116693933588480)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(293873587705571)}, boost::int128::uint128_t{UINT64_C(16177650375369096972), UINT64_C(10277214349659471872)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(2938735877055718)}, boost::int128::uint128_t{UINT64_C(14202551164014556797), UINT64_C(10538423128046960640)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(29387358770557187)}, boost::int128::uint128_t{UINT64_C(12898303124178706663), UINT64_C(13150510911921848320)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(293873587705571876)}, boost::int128::uint128_t{UINT64_C(18302566799529756941), UINT64_C(2377900603251621888)}}, - u256{boost::int128::uint128_t{UINT64_C(0), UINT64_C(2938735877055718769)}, boost::int128::uint128_t{UINT64_C(17004971331911604867), UINT64_C(5332261958806667264)}}, - u256{boost::int128::uint128_t{UINT64_C(1), UINT64_C(10940614696847636083)}, boost::int128::uint128_t{UINT64_C(4029016655730084128), UINT64_C(16429131440647569408)}}, - u256{boost::int128::uint128_t{UINT64_C(15), UINT64_C(17172426599928602752)}, boost::int128::uint128_t{UINT64_C(3396678409881738056), UINT64_C(16717361816799281152)}}, - u256{boost::int128::uint128_t{UINT64_C(159), UINT64_C(5703569335900062977)}, boost::int128::uint128_t{UINT64_C(15520040025107828953), UINT64_C(1152921504606846976)}}, - u256{boost::int128::uint128_t{UINT64_C(1593), UINT64_C(1695461137871974930)}, boost::int128::uint128_t{UINT64_C(7626447661401876602), UINT64_C(11529215046068469760)}}, - u256{boost::int128::uint128_t{UINT64_C(15930), UINT64_C(16954611378719749304)}, boost::int128::uint128_t{UINT64_C(2477500319180559562), UINT64_C(4611686018427387904)}}, - u256{boost::int128::uint128_t{UINT64_C(159309), UINT64_C(3525417123811528497)}, boost::int128::uint128_t{UINT64_C(6328259118096044006), UINT64_C(9223372036854775808)}}, - u256{boost::int128::uint128_t{UINT64_C(1593091), UINT64_C(16807427164405733357)}, boost::int128::uint128_t{UINT64_C(7942358959831785217), UINT64_C(0)}}, - u256{boost::int128::uint128_t{UINT64_C(15930919), UINT64_C(2053574980671369030)}, boost::int128::uint128_t{UINT64_C(5636613303479645706), UINT64_C(0)}}, - u256{boost::int128::uint128_t{UINT64_C(159309191), UINT64_C(2089005733004138687)}, boost::int128::uint128_t{UINT64_C(1025900813667802212), UINT64_C(0)}}, - u256{boost::int128::uint128_t{UINT64_C(1593091911), UINT64_C(2443313256331835254)}, boost::int128::uint128_t{UINT64_C(10259008136678022120), UINT64_C(0)}}, - u256{boost::int128::uint128_t{UINT64_C(15930919111), UINT64_C(5986388489608800929)}, boost::int128::uint128_t{UINT64_C(10356360998232463120), UINT64_C(0)}}, - u256{boost::int128::uint128_t{UINT64_C(159309191113), UINT64_C(4523652674959354447)}, boost::int128::uint128_t{UINT64_C(11329889613776873120), UINT64_C(0)}}, - u256{boost::int128::uint128_t{UINT64_C(1593091911132), UINT64_C(8343038602174441244)}, boost::int128::uint128_t{UINT64_C(2618431695511421504), UINT64_C(0)}}, - u256{boost::int128::uint128_t{UINT64_C(15930919111324), UINT64_C(9643409726906205977)}, boost::int128::uint128_t{UINT64_C(7737572881404663424), UINT64_C(0)}}, - u256{boost::int128::uint128_t{UINT64_C(159309191113245), UINT64_C(4200376900514301694)}, boost::int128::uint128_t{UINT64_C(3588752519208427776), UINT64_C(0)}}, - u256{boost::int128::uint128_t{UINT64_C(1593091911132452), UINT64_C(5110280857723913709)}, boost::int128::uint128_t{UINT64_C(17440781118374726144), UINT64_C(0)}}, - u256{boost::int128::uint128_t{UINT64_C(15930919111324522), UINT64_C(14209320429820033867)}, boost::int128::uint128_t{UINT64_C(8387114520361296896), UINT64_C(0)}}, - u256{boost::int128::uint128_t{UINT64_C(159309191113245227), UINT64_C(12965995782233477362)}, boost::int128::uint128_t{UINT64_C(10084168908774762496), UINT64_C(0)}}, - u256{boost::int128::uint128_t{UINT64_C(1593091911132452277), UINT64_C(532749306367912313)}, boost::int128::uint128_t{UINT64_C(8607968719199866880), UINT64_C(0)}}, - u256{boost::int128::uint128_t{UINT64_C(15930919111324522770), UINT64_C(5327493063679123134)}, boost::int128::uint128_t{UINT64_C(12292710897160462336), UINT64_C(0)}}, +BOOST_DECIMAL_INLINE_CONSTEXPR_VARIABLE u256 u256_pow_10[78] = { + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[0]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[1]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[2]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[3]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[4]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[5]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[6]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[7]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[8]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[9]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[10]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[11]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[12]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[13]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[14]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[15]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[16]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[17]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[18]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[19]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[20]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[21]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[22]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[23]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[24]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[25]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[26]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[27]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[28]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[29]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[30]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[31]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[32]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[33]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[34]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[35]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[36]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[37]}, + u256{BOOST_DECIMAL_DETAIL_INT128_pow10[38]}, + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[1]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[2]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[3]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[4]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[5]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[6]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[7]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[8]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[9]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[10]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[11]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[12]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[13]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[14]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[15]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[16]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[17]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[18]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[19]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[20]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[21]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[22]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[23]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[24]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[25]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[26]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[27]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[28]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[29]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[30]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[31]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[32]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[33]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[34]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[35]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[36]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[37]), + umul256(BOOST_DECIMAL_DETAIL_INT128_pow10[38], BOOST_DECIMAL_DETAIL_INT128_pow10[38]) }; } // namespace impl diff --git a/test/Jamfile b/test/Jamfile index 66f1b598c..4f20149c4 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -70,6 +70,7 @@ run github_issue_1057.cpp ; compile-fail github_issue_1087.cpp ; run github_issue_1091.cpp ; run github_issue_1094.cpp ; +run github_issue_1110.cpp ; run github_issue_1112.cpp ; run link_1.cpp link_2.cpp link_3.cpp ; diff --git a/test/github_issue_1110.cpp b/test/github_issue_1110.cpp new file mode 100644 index 000000000..3a3c27d76 --- /dev/null +++ b/test/github_issue_1110.cpp @@ -0,0 +1,68 @@ +// Copyright 2025 Christopher Kormanyos +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt +// +// See: https://github.com/cppalliance/decimal/issues/1110 + +#include +#include +#include + +#include + +#include +#include +#include + +using namespace boost::decimal; + +namespace local { + +auto test() -> void; + +auto test() -> void +{ + const boost::decimal::decimal128_t one { 1 }; + const boost::decimal::decimal128_t del { 1, -32 }; + const boost::decimal::decimal128_t sum { one + del }; + + const boost::decimal::decimal128_t sqr { sqrt(sum) }; + + { + std::stringstream strm { }; + + strm << std::setprecision(std::numeric_limits::digits10) << sqr; + + BOOST_TEST_CSTR_EQ(strm.str().c_str(), "1.000000000000000000000000000000005"); + } + + const boost::decimal::decimal128_t cbr { cbrt(sum) }; + + { + std::stringstream strm { }; + + strm << std::setprecision(std::numeric_limits::digits10)<< cbr; + + // TODO: This tolerance isn't the best + BOOST_TEST_CSTR_EQ(strm.str().c_str(), "1.000000000000000000000000000000641"); + } + + const boost::decimal::decimal128_t lgt { log10(sum) }; + + { + std::stringstream strm { }; + + strm << std::setprecision(std::numeric_limits::digits10)<< lgt; + + BOOST_TEST_CSTR_EQ(strm.str().c_str(), "4.4e-33"); + } +} + +} // namespace local + +auto main() -> int +{ + local::test(); + + return boost::report_errors(); +} diff --git a/test/test_remove_trailing_zeros.cpp b/test/test_remove_trailing_zeros.cpp index 3e58a63a9..4a66a53f8 100644 --- a/test/test_remove_trailing_zeros.cpp +++ b/test/test_remove_trailing_zeros.cpp @@ -39,30 +39,11 @@ void test() void test_extended() { using namespace boost::decimal; - constexpr std::array powers_of_10 = - {{ - boost::int128::uint128_t {UINT64_C(0x5), UINT64_C(0x6BC75E2D63100000)}, - boost::int128::uint128_t {UINT64_C(0x36), UINT64_C(0x35C9ADC5DEA00000)}, - boost::int128::uint128_t {UINT64_C(0x21E), UINT64_C(0x19E0C9BAB2400000)}, - boost::int128::uint128_t {UINT64_C(0x152D), UINT64_C(0x02C7E14AF6800000)}, - boost::int128::uint128_t {UINT64_C(0x84595), UINT64_C(0x161401484A000000)}, - boost::int128::uint128_t {UINT64_C(0x52B7D2), UINT64_C(0xDCC80CD2E4000000)}, - boost::int128::uint128_t {UINT64_C(0x33B2E3C), UINT64_C(0x9FD0803CE8000000)}, - boost::int128::uint128_t {UINT64_C(0x204FCE5E), UINT64_C(0x3E25026110000000)}, - boost::int128::uint128_t {UINT64_C(0x1431E0FAE), UINT64_C(0x6D7217CAA0000000)}, - boost::int128::uint128_t {UINT64_C(0xC9F2C9CD0), UINT64_C(0x4674EDEA40000000)}, - boost::int128::uint128_t {UINT64_C(0x7E37BE2022), UINT64_C(0xC0914B2680000000)}, - boost::int128::uint128_t {UINT64_C(0x4EE2D6D415B), UINT64_C(0x85ACEF8100000000)}, - boost::int128::uint128_t {UINT64_C(0x314DC6448D93), UINT64_C(0x38C15B0A00000000)}, - boost::int128::uint128_t {UINT64_C(0x1ED09BEAD87C0), UINT64_C(0x378D8E6400000000)}, - boost::int128::uint128_t {UINT64_C(0x13426172C74D82), UINT64_C(0x2B878FE800000000)}, - boost::int128::uint128_t {UINT64_C(0xC097CE7BC90715), UINT64_C(0xB34B9F1000000000)}, - boost::int128::uint128_t {UINT64_C(0x785EE10D5DA46D9), UINT64_C(0x00F436A000000000)}, - boost::int128::uint128_t {UINT64_C(0x4B3B4CA85A86C47A), UINT64_C(0x098A224000000000)} - }}; + const auto powers_of_10 = detail::impl::BOOST_DECIMAL_DETAIL_INT128_pow10; - for (const auto& val : powers_of_10) + for (std::size_t i {}; i < 39; ++i) { + const auto val = powers_of_10[i]; const auto temp {boost::decimal::detail::remove_trailing_zeros(val)}; if (!BOOST_TEST_EQ(temp.trimmed_number, boost::int128::uint128_t(1))) {