// Copyright 2023 Matt Borland // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt #ifndef BOOST_DECIMAL_DETAIL_CMATH_FMAX_HPP #define BOOST_DECIMAL_DETAIL_CMATH_FMAX_HPP #include #include #include #include #include #ifndef BOOST_DECIMAL_BUILD_MODULE #include #include #endif namespace boost { namespace decimal { BOOST_DECIMAL_EXPORT template constexpr auto fmax(const T1 lhs, const T2 rhs) noexcept BOOST_DECIMAL_REQUIRES_TWO(detail::is_decimal_floating_point_v, T1, detail::is_decimal_floating_point_v, T2) { using promoted_type = detail::promote_args_t; #ifndef BOOST_DECIMAL_FAST_MATH if (isnan(lhs) && !isnan(rhs)) { if (issignaling(lhs)) { return nan_conversion(lhs); } else { return static_cast(rhs); } } else if ((!isnan(lhs) && isnan(rhs)) || (isnan(lhs) && isnan(rhs))) { if (issignaling(lhs)) { return nan_conversion(lhs); } else if (issignaling(rhs)) { return nan_conversion(rhs); } else { return static_cast(lhs); } } #endif return lhs > rhs ? static_cast(lhs) : static_cast(rhs); } } // namespace decimal } // namespace boost #endif // BOOST_DECIMAL_DETAIL_CMATH_FMAX_HPP