Skip to content
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
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/cbrt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ constexpr auto cbrt_impl(const T x) noexcept
remove_trailing_zeros(gn)
};

const bool is_pure { static_cast<unsigned>(zeros_removal.trimmed_number) == 1U };
const bool is_pure { zeros_removal.trimmed_number == 1U };

if(is_pure)
{
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/log10.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ constexpr auto log10_impl(const T x) noexcept
remove_trailing_zeros(gn)
};

const bool is_pure { static_cast<unsigned>(zeros_removal.trimmed_number) == 1U };
const bool is_pure { zeros_removal.trimmed_number == 1U };

if(is_pure)
{
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/sqrt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ constexpr auto sqrt_impl(const T x) noexcept
remove_trailing_zeros(gn)
};

const bool is_pure { static_cast<unsigned>(zeros_removal.trimmed_number) == 1U };
const bool is_pure { zeros_removal.trimmed_number == 1U };

constexpr T one { 1 };

Expand Down
243 changes: 119 additions & 124 deletions include/boost/decimal/detail/power_tables.hpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down
68 changes: 68 additions & 0 deletions test/github_issue_1110.cpp
Original file line number Diff line number Diff line change
@@ -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 <boost/decimal/decimal128_t.hpp>
#include <boost/decimal/cmath.hpp>
#include <boost/decimal/iostream.hpp>

#include <boost/core/lightweight_test.hpp>

#include <iomanip>
#include <iostream>
#include <sstream>

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<boost::decimal::decimal128_t>::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<boost::decimal::decimal128_t>::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<boost::decimal::decimal128_t>::digits10)<< lgt;

BOOST_TEST_CSTR_EQ(strm.str().c_str(), "4.4e-33");
}
}

} // namespace local

auto main() -> int
{
local::test();

return boost::report_errors();
}
25 changes: 3 additions & 22 deletions test/test_remove_trailing_zeros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,11 @@ void test()
void test_extended()
{
using namespace boost::decimal;
constexpr std::array<boost::int128::uint128_t, 18> 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)))
{
Expand Down