Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:45:14

0001 //  (C) Copyright Matt Borland 2022.
0002 //  Use, modification and distribution are subject to the
0003 //  Boost Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_MATH_CCMATH_FMAX_HPP
0007 #define BOOST_MATH_CCMATH_FMAX_HPP
0008 
0009 #include <boost/math/ccmath/detail/config.hpp>
0010 
0011 #ifdef BOOST_MATH_NO_CCMATH
0012 #error "The header <boost/math/fmax.hpp> can only be used in C++17 and later."
0013 #endif
0014 
0015 #include <boost/math/tools/promotion.hpp>
0016 #include <boost/math/ccmath/isnan.hpp>
0017 
0018 namespace boost::math::ccmath {
0019 
0020 namespace detail {
0021 
0022 template <typename T>
0023 constexpr T fmax_impl(const T x, const T y) noexcept
0024 {
0025     if (x > y)
0026     {
0027         return x;
0028     }
0029     else
0030     {
0031         return y;
0032     }
0033 }
0034 
0035 } // Namespace detail
0036 
0037 template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true>
0038 constexpr Real fmax(Real x, Real y) noexcept
0039 {
0040     if (BOOST_MATH_IS_CONSTANT_EVALUATED(x))
0041     {
0042         if (boost::math::ccmath::isnan(x))
0043         {
0044             return y;
0045         }
0046         else if (boost::math::ccmath::isnan(y))
0047         {
0048             return x;
0049         }
0050         
0051         return boost::math::ccmath::detail::fmax_impl(x, y);
0052     }
0053     else
0054     {
0055         using std::fmax;
0056         return fmax(x, y);
0057     }
0058 }
0059 
0060 template <typename T1, typename T2>
0061 constexpr auto fmax(T1 x, T2 y) noexcept
0062 {
0063     if (BOOST_MATH_IS_CONSTANT_EVALUATED(x))
0064     {
0065         using promoted_type = boost::math::tools::promote_args_2_t<T1, T2>;
0066         return boost::math::ccmath::fmax(static_cast<promoted_type>(x), static_cast<promoted_type>(y));
0067     }
0068     else
0069     {
0070         using std::fmax;
0071         return fmax(x, y);
0072     }
0073 }
0074 
0075 constexpr float fmaxf(float x, float y) noexcept
0076 {
0077     return boost::math::ccmath::fmax(x, y);
0078 }
0079 
0080 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
0081 constexpr long double fmaxl(long double x, long double y) noexcept
0082 {
0083     return boost::math::ccmath::fmax(x, y);
0084 }
0085 #endif
0086 
0087 } // Namespace boost::math::ccmath
0088 
0089 #endif // BOOST_MATH_CCMATH_FMAX_HPP