Skip to content

Commit 53a0e59

Browse files
authored
Merge pull request #741 from boostorg/more_double_fp_syntax
More double_fp syntax improvements
2 parents f40742c + 6ffeac8 commit 53a0e59

File tree

3 files changed

+121
-106
lines changed

3 files changed

+121
-106
lines changed

include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath_log.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ constexpr auto log_impl(Real x) noexcept -> Real
125125
{
126126
int n2 { };
127127

128+
// Scale the argument down.
129+
128130
Real x2 { ::boost::multiprecision::backends::cpp_df_qf_detail::ccmath::detail::frexp_impl(x, &n2) };
129131

130132
if (x2 > static_cast<Real>(0.875L))
@@ -134,18 +136,17 @@ constexpr auto log_impl(Real x) noexcept -> Real
134136
++n2;
135137
}
136138

137-
Real s { log_impl_pade(x2) };
139+
// Estimate the logarithm of the argument to roughly half
140+
// the precision of Real.
141+
const Real s { log_impl_pade(x2) };
138142

143+
// Compute the exponent function to the full precision of Real.
139144
const Real E { exp_impl(s) };
140145

141-
// Do one single step of Newton-Raphson iteration.
142-
s = s + ((x2 - E) / E);
143-
144-
Real xn2 { static_cast<Real>(n2) * constant_ln_two<Real>() };
145-
146-
s += xn2;
146+
// Perform one single step of Newton-Raphson iteration
147+
// and scale the result back up.
147148

148-
return s;
149+
return (s + ((x2 - E) / E)) + Real { static_cast<Real>(n2) * constant_ln_two<Real>() };
149150
}
150151
// LCOV_EXCL_STOP
151152

0 commit comments

Comments
 (0)