Skip to content

Commit

Permalink
Cast integer inputs to double like STL
Browse files Browse the repository at this point in the history
  • Loading branch information
mborland committed Nov 15, 2022
1 parent 054214c commit 8d805b4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/boost/math/special_functions/log1p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,21 @@ inline typename tools::promote_args<T>::type log1p(T x)
{
return boost::math::log1p(x, policies::policy<>());
}

// Standard library casts integer inputs of special functions to double so follow precedence
// See: https://en.cppreference.com/w/cpp/numeric/math/log1p
template <BOOST_MATH_ARBITRARY_INTEGER T>
inline tools::promote_args_t<T> log1p(T x)
{
return boost::math::log1p(static_cast<double>(x), policies::policy<>());
}

template <BOOST_MATH_ARBITRARY_INTEGER T, BOOST_MATH_POLICY Policy>
inline tools::promote_args_t<T> log1p(T x, const Policy& pol)
{
return boost::math::log1p(static_cast<double>(x), pol);
}

//
// Compute log(1+x)-x:
//
Expand Down

0 comments on commit 8d805b4

Please sign in to comment.