// (C) Copyright Matt Borland 2021. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef ACTIV_BOOST_MATH_CCMATH_MODF_HPP #define ACTIV_BOOST_MATH_CCMATH_MODF_HPP #include #include #include #include #include #include #include #include namespace Boost::math::ccmath { namespace detail { template inline constexpr Real modf_error_impl(Real x, Real* iptr) { *iptr = x; return Boost::math::ccmath::abs(x) == Real(0) ? x : x > Real(0) ? Real(0) : -Real(0); } template inline constexpr Real modf_nan_impl(Real x, Real* iptr) { *iptr = x; return x; } template inline constexpr Real modf_impl(Real x, Real* iptr) { *iptr = Boost::math::ccmath::trunc(x); return (x - *iptr); } } // Namespace detail template inline constexpr Real modf(Real x, Real* iptr) { if(ACTIV_BOOST_MATH_IS_CONSTANT_EVALUATED(x)) { return Boost::math::ccmath::abs(x) == Real(0) ? detail::modf_error_impl(x, iptr) : Boost::math::ccmath::isinf(x) ? detail::modf_error_impl(x, iptr) : Boost::math::ccmath::isnan(x) ? detail::modf_nan_impl(x, iptr) : Boost::math::ccmath::detail::modf_impl(x, iptr); } else { using std::modf; return modf(x, iptr); } } inline constexpr float modff(float x, float* iptr) { return Boost::math::ccmath::modf(x, iptr); } #ifndef ACTIV_BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS inline constexpr long double modfl(long double x, long double* iptr) { return Boost::math::ccmath::modf(x, iptr); } #endif } // Namespaces #endif // ACTIV_BOOST_MATH_CCMATH_MODF_HPP