Back to home page

EIC code displayed by LXR

 
 

    


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

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_CEIL_HPP
0007 #define BOOST_MATH_CCMATH_CEIL_HPP
0008 
0009 #include <boost/math/ccmath/detail/config.hpp>
0010 
0011 #ifdef BOOST_MATH_NO_CCMATH
0012 #error "The header <boost/math/ceil.hpp> can only be used in C++17 and later."
0013 #endif
0014 
0015 #include <boost/math/ccmath/floor.hpp>
0016 #include <boost/math/ccmath/abs.hpp>
0017 #include <boost/math/ccmath/isinf.hpp>
0018 #include <boost/math/ccmath/isnan.hpp>
0019 
0020 namespace boost::math::ccmath {
0021 
0022 namespace detail {
0023 
0024 template <typename T>
0025 inline constexpr T ceil_impl(T arg) noexcept
0026 {
0027     T result = boost::math::ccmath::floor(arg);
0028 
0029     if(result == arg)
0030     {
0031         return result;
0032     }
0033     else
0034     {
0035         return result + 1;
0036     }
0037 }
0038 
0039 } // Namespace detail
0040 
0041 template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true>
0042 inline constexpr Real ceil(Real arg) noexcept
0043 {
0044     if(BOOST_MATH_IS_CONSTANT_EVALUATED(arg))
0045     {
0046         return boost::math::ccmath::abs(arg) == Real(0) ? arg :
0047                boost::math::ccmath::isinf(arg) ? arg :
0048                boost::math::ccmath::isnan(arg) ? arg :
0049                boost::math::ccmath::detail::ceil_impl(arg);
0050     }
0051     else
0052     {
0053         using std::ceil;
0054         return ceil(arg);
0055     }
0056 }
0057 
0058 template <typename Z, std::enable_if_t<std::is_integral_v<Z>, bool> = true>
0059 inline constexpr double ceil(Z arg) noexcept
0060 {
0061     return boost::math::ccmath::ceil(static_cast<double>(arg));
0062 }
0063 
0064 inline constexpr float ceilf(float arg) noexcept
0065 {
0066     return boost::math::ccmath::ceil(arg);
0067 }
0068 
0069 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
0070 inline constexpr long double ceill(long double arg) noexcept
0071 {
0072     return boost::math::ccmath::ceil(arg);
0073 }
0074 #endif
0075 
0076 } // Namespaces
0077 
0078 #endif // BOOST_MATH_CCMATH_CEIL_HPP