From 8d805b448b6eced8e380f3d68a4314e1b403371b Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 14 Nov 2022 19:07:22 -0800 Subject: [PATCH] Cast integer inputs to double like STL --- include/boost/math/special_functions/log1p.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/boost/math/special_functions/log1p.hpp b/include/boost/math/special_functions/log1p.hpp index b3ecf4cbaa..2579dafe87 100644 --- a/include/boost/math/special_functions/log1p.hpp +++ b/include/boost/math/special_functions/log1p.hpp @@ -430,6 +430,21 @@ inline typename tools::promote_args::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 +inline tools::promote_args_t log1p(T x) +{ + return boost::math::log1p(static_cast(x), policies::policy<>()); +} + +template +inline tools::promote_args_t log1p(T x, const Policy& pol) +{ + return boost::math::log1p(static_cast(x), pol); +} + // // Compute log(1+x)-x: //