mirror of
https://github.com/boostorg/math.git
synced 2026-02-25 16:32:15 +00:00
Improve handling of NANs in fdim
This commit is contained in:
@@ -17,7 +17,7 @@ namespace boost::math::ccmath {
|
||||
namespace detail {
|
||||
|
||||
template <typename T>
|
||||
inline constexpr T fdim_impl(const T x, const T y) noexcept
|
||||
constexpr T fdim_impl(const T x, const T y) noexcept
|
||||
{
|
||||
if (x <= y)
|
||||
{
|
||||
@@ -36,13 +36,20 @@ inline constexpr T fdim_impl(const T x, const T y) noexcept
|
||||
} // Namespace detail
|
||||
|
||||
template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true>
|
||||
inline constexpr Real fdim(Real x, Real y) noexcept
|
||||
constexpr Real fdim(Real x, Real y) noexcept
|
||||
{
|
||||
if (BOOST_MATH_IS_CONSTANT_EVALUATED(x))
|
||||
{
|
||||
return boost::math::ccmath::isnan(x) ? std::numeric_limits<Real>::quiet_NaN() :
|
||||
boost::math::ccmath::isnan(y) ? std::numeric_limits<Real>::quiet_NaN() :
|
||||
boost::math::ccmath::detail::fdim_impl(x, y);
|
||||
if (boost::math::ccmath::isnan(x))
|
||||
{
|
||||
return x;
|
||||
}
|
||||
else if (boost::math::ccmath::isnan(y))
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
return boost::math::ccmath::detail::fdim_impl(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -52,7 +59,7 @@ inline constexpr Real fdim(Real x, Real y) noexcept
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
inline constexpr auto fdim(T1 x, T2 y) noexcept
|
||||
constexpr auto fdim(T1 x, T2 y) noexcept
|
||||
{
|
||||
if (BOOST_MATH_IS_CONSTANT_EVALUATED(x))
|
||||
{
|
||||
@@ -83,13 +90,13 @@ inline constexpr auto fdim(T1 x, T2 y) noexcept
|
||||
}
|
||||
}
|
||||
|
||||
inline constexpr float fdimf(float x, float y) noexcept
|
||||
constexpr float fdimf(float x, float y) noexcept
|
||||
{
|
||||
return boost::math::ccmath::fdim(x, y);
|
||||
}
|
||||
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
inline constexpr long double fdiml(long double x, long double y) noexcept
|
||||
constexpr long double fdiml(long double x, long double y) noexcept
|
||||
{
|
||||
return boost::math::ccmath::fdim(x, y);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user