2
0
mirror of https://github.com/boostorg/math.git synced 2026-02-26 04:42:22 +00:00

Simplify fmax type promotion logic

This commit is contained in:
Matt Borland
2023-01-03 14:29:29 +01:00
parent d27c7f43e6
commit 5ebeddef31

View File

@@ -10,6 +10,7 @@
#include <limits>
#include <type_traits>
#include <boost/math/tools/is_constant_evaluated.hpp>
#include <boost/math/tools/promotion.hpp>
#include <boost/math/ccmath/isnan.hpp>
namespace boost::math::ccmath {
@@ -59,25 +60,8 @@ constexpr auto fmax(T1 x, T2 y) noexcept
{
if (BOOST_MATH_IS_CONSTANT_EVALUATED(x))
{
// If the type is an integer (e.g. epsilon == 0) then set the epsilon value to 1 so that type is at a minimum
// cast to double
constexpr auto T1p = std::numeric_limits<T1>::epsilon() > 0 ? std::numeric_limits<T1>::epsilon() : 1;
constexpr auto T2p = std::numeric_limits<T2>::epsilon() > 0 ? std::numeric_limits<T2>::epsilon() : 1;
using promoted_type =
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
std::conditional_t<T1p <= LDBL_EPSILON && T1p <= T2p, T1,
std::conditional_t<T2p <= LDBL_EPSILON && T2p <= T1p, T2,
#endif
std::conditional_t<T1p <= DBL_EPSILON && T1p <= T2p, T1,
std::conditional_t<T2p <= DBL_EPSILON && T2p <= T1p, T2, double
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
>>>>;
#else
>>;
#endif
return boost::math::ccmath::fmax(promoted_type(x), promoted_type(y));
using promoted_type = boost::math::tools::promote_args_2_t<T1, T2>;
return boost::math::ccmath::fmax(static_cast<promoted_type>(x), static_cast<promoted_type>(y));
}
else
{