Skip to content

Commit a84e076

Browse files
committed
Up the Newton iterations in cbrt
1 parent e083c2a commit a84e076

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

include/boost/decimal/detail/cmath/cbrt.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ constexpr auto cbrt_impl(const T x) noexcept
131131
(five + gx * (seventy + gx * 56))
132132
/ (numbers::cbrt2_v<T> * (fourteen + gx * (seventy + gx * 20)));
133133

134-
// Perform 2, 3 or 4 Newton-Raphson iterations depending on precision.
134+
// Perform 3, 4 or 5 Newton-Raphson iterations depending on precision.
135135
// Note from above, we start with slightly more than 2 decimal digits
136136
// of accuracy.
137137

138138
constexpr int iter_loops
139139
{
140-
std::numeric_limits<T>::digits10 < 10 ? 2
141-
: std::numeric_limits<T>::digits10 < 20 ? 3 : 4
140+
std::numeric_limits<T>::digits10 < 10 ? 3
141+
: std::numeric_limits<T>::digits10 < 20 ? 4 : 5
142142
};
143143

144144
for (int idx = 0; idx < iter_loops; ++idx)

include/boost/decimal/detail/cmath/sqrt.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ constexpr auto sqrt_impl(const T x) noexcept
123123
(one + gx * ((one + gx) * 20))
124124
/ (numbers::sqrt2_v<T> * ((gx * 4) * (five + gx) + five));
125125

126-
// Perform 2, 3 or 4 Newton-Raphson iterations depending on precision.
126+
// Perform 3, 4 or 5 Newton-Raphson iterations depending on precision.
127127
// Note from above, we start with slightly more than 2 decimal digits
128128
// of accuracy.
129129

test/github_issue_1110.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ auto test() -> void
4343

4444
strm << std::setprecision(std::numeric_limits<boost::decimal::decimal128_t>::digits10)<< cbr;
4545

46-
// TODO: This tolerance isn't the best
47-
BOOST_TEST_CSTR_EQ(strm.str().c_str(), "1.000000000000000000000000000000641");
46+
BOOST_TEST_CSTR_EQ(strm.str().c_str(), "1.000000000000000000000000000000003");
4847
}
4948

5049
const boost::decimal::decimal128_t lgt { log10(sum) };

0 commit comments

Comments
 (0)