Skip to content

Commit 8d805b4

Browse files
committed
Cast integer inputs to double like STL
1 parent 054214c commit 8d805b4

File tree

1 file changed

+15
-0
lines changed
  • include/boost/math/special_functions

1 file changed

+15
-0
lines changed

include/boost/math/special_functions/log1p.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,21 @@ inline typename tools::promote_args<T>::type log1p(T x)
430430
{
431431
return boost::math::log1p(x, policies::policy<>());
432432
}
433+
434+
// Standard library casts integer inputs of special functions to double so follow precedence
435+
// See: https://en.cppreference.com/w/cpp/numeric/math/log1p
436+
template <BOOST_MATH_ARBITRARY_INTEGER T>
437+
inline tools::promote_args_t<T> log1p(T x)
438+
{
439+
return boost::math::log1p(static_cast<double>(x), policies::policy<>());
440+
}
441+
442+
template <BOOST_MATH_ARBITRARY_INTEGER T, BOOST_MATH_POLICY Policy>
443+
inline tools::promote_args_t<T> log1p(T x, const Policy& pol)
444+
{
445+
return boost::math::log1p(static_cast<double>(x), pol);
446+
}
447+
433448
//
434449
// Compute log(1+x)-x:
435450
//

0 commit comments

Comments
 (0)