123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- namespace boost::math::ccmath {
- namespace detail {
- template <typename T>
- constexpr T fma_imp(const T x, const T y, const T z) noexcept
- {
- #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(__INTEL_LLVM_COMPILER)
- if constexpr (std::is_same_v<T, float>)
- {
- return __builtin_fmaf(x, y, z);
- }
- else if constexpr (std::is_same_v<T, double>)
- {
- return __builtin_fma(x, y, z);
- }
- else if constexpr (std::is_same_v<T, long double>)
- {
- return __builtin_fmal(x, y, z);
- }
-
-
-
- return (x * y) + z;
- }
- }
- template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true>
- constexpr Real fma(Real x, Real y, Real z) noexcept
- {
- if (BOOST_MATH_IS_CONSTANT_EVALUATED(x))
- {
- if (x == 0 && boost::math::ccmath::isinf(y))
- {
- return std::numeric_limits<Real>::quiet_NaN();
- }
- else if (y == 0 && boost::math::ccmath::isinf(x))
- {
- return std::numeric_limits<Real>::quiet_NaN();
- }
- else if (boost::math::ccmath::isnan(x))
- {
- return std::numeric_limits<Real>::quiet_NaN();
- }
- else if (boost::math::ccmath::isnan(y))
- {
- return std::numeric_limits<Real>::quiet_NaN();
- }
- else if (boost::math::ccmath::isnan(z))
- {
- return std::numeric_limits<Real>::quiet_NaN();
- }
- return boost::math::ccmath::detail::fma_imp(x, y, z);
- }
- else
- {
- using std::fma;
- return fma(x, y, z);
- }
- }
- template <typename T1, typename T2, typename T3>
- constexpr auto fma(T1 x, T2 y, T3 z) noexcept
- {
- if (BOOST_MATH_IS_CONSTANT_EVALUATED(x))
- {
-
-
- 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;
- constexpr auto T3p = std::numeric_limits<T3>::epsilon() > 0 ? std::numeric_limits<T3>::epsilon() : 1;
- using promoted_type =
-
- std::conditional_t<T1p <= LDBL_EPSILON && T1p <= T2p, T1,
- std::conditional_t<T2p <= LDBL_EPSILON && T2p <= T1p, T2,
- std::conditional_t<T3p <= LDBL_EPSILON && T3p <= T2p, T3,
-
- std::conditional_t<T1p <= DBL_EPSILON && T1p <= T2p, T1,
- std::conditional_t<T2p <= DBL_EPSILON && T2p <= T1p, T2,
- std::conditional_t<T3p <= DBL_EPSILON && T3p <= T2p, T3, double
-
- >>>>>>;
-
- >>>;
-
- return boost::math::ccmath::fma(promoted_type(x), promoted_type(y), promoted_type(z));
- }
- else
- {
- using std::fma;
- return fma(x, y, z);
- }
- }
- constexpr float fmaf(float x, float y, float z) noexcept
- {
- return boost::math::ccmath::fma(x, y, z);
- }
- constexpr long double fmal(long double x, long double y, long double z) noexcept
- {
- return boost::math::ccmath::fma(x, y, z);
- }
- }
|