Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //  (C) Copyright Matt Borland 2021.
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_MODF_HPP
0007 #define BOOST_MATH_CCMATH_MODF_HPP
0008 
0009 #include <boost/math/ccmath/detail/config.hpp>
0010 
0011 #ifdef BOOST_MATH_NO_CCMATH
0012 #error "The header <boost/math/modf.hpp> can only be used in C++17 and later."
0013 #endif
0014 
0015 #include <boost/math/ccmath/abs.hpp>
0016 #include <boost/math/ccmath/isinf.hpp>
0017 #include <boost/math/ccmath/isnan.hpp>
0018 #include <boost/math/ccmath/trunc.hpp>
0019 
0020 namespace boost::math::ccmath {
0021 
0022 namespace detail {
0023 
0024 template <typename Real>
0025 inline constexpr Real modf_error_impl(Real x, Real* iptr)
0026 {
0027     *iptr = x;
0028     return boost::math::ccmath::abs(x) == Real(0) ? x :
0029            x > Real(0) ? Real(0) : -Real(0);
0030 }
0031 
0032 template <typename Real>
0033 inline constexpr Real modf_nan_impl(Real x, Real* iptr)
0034 {
0035     *iptr = x;
0036     return x;
0037 }
0038 
0039 template <typename Real>
0040 inline constexpr Real modf_impl(Real x, Real* iptr)
0041 {
0042     *iptr = boost::math::ccmath::trunc(x);
0043     return (x - *iptr);
0044 }
0045 
0046 } // Namespace detail
0047 
0048 template <typename Real>
0049 inline constexpr Real modf(Real x, Real* iptr)
0050 {
0051     if(BOOST_MATH_IS_CONSTANT_EVALUATED(x))
0052     {
0053         return boost::math::ccmath::abs(x) == Real(0) ? detail::modf_error_impl(x, iptr) :
0054                boost::math::ccmath::isinf(x) ? detail::modf_error_impl(x, iptr) :
0055                boost::math::ccmath::isnan(x) ? detail::modf_nan_impl(x, iptr) :
0056                boost::math::ccmath::detail::modf_impl(x, iptr);
0057     }
0058     else
0059     {
0060         using std::modf;
0061         return modf(x, iptr);
0062     }
0063 }
0064 
0065 inline constexpr float modff(float x, float* iptr)
0066 {
0067     return boost::math::ccmath::modf(x, iptr);
0068 }
0069 
0070 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
0071 inline constexpr long double modfl(long double x, long double* iptr)
0072 {
0073     return boost::math::ccmath::modf(x, iptr);
0074 }
0075 #endif
0076 
0077 } // Namespaces
0078 
0079 #endif // BOOST_MATH_CCMATH_MODF_HPP