File indexing completed on 2025-01-30 09:45:14
0001
0002
0003
0004
0005
0006 #ifndef BOOST_MATH_CCMATH_FMIN_HPP
0007 #define BOOST_MATH_CCMATH_FMIN_HPP
0008
0009 #include <boost/math/ccmath/detail/config.hpp>
0010
0011 #ifdef BOOST_MATH_NO_CCMATH
0012 #error "The header <boost/math/fmin.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 fmin_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 }
0036
0037 template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true>
0038 constexpr Real fmin(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::fmin_impl(x, y);
0052 }
0053 else
0054 {
0055 using std::fmin;
0056 return fmin(x, y);
0057 }
0058 }
0059
0060 template <typename T1, typename T2>
0061 constexpr auto fmin(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::fmin(static_cast<promoted_type>(x), static_cast<promoted_type>(y));
0067 }
0068 else
0069 {
0070 using std::fmin;
0071 return fmin(x, y);
0072 }
0073 }
0074
0075 float fminf(float x, float y) noexcept
0076 {
0077 return boost::math::ccmath::fmin(x, y);
0078 }
0079
0080 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
0081 long double fminl(long double x, long double y) noexcept
0082 {
0083 return boost::math::ccmath::fmin(x, y);
0084 }
0085 #endif
0086
0087 }
0088
0089 #endif