79 lines · plain
1// (C) Copyright Matt Borland 2021.2// Use, modification and distribution are subject to the3// Boost Software License, Version 1.0. (See accompanying file4// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)5 6#ifndef BOOST_MATH_CCMATH_CEIL_HPP7#define BOOST_MATH_CCMATH_CEIL_HPP8 9#include <boost/math/ccmath/detail/config.hpp>10 11#ifdef BOOST_MATH_NO_CCMATH12#error "The header <boost/math/ceil.hpp> can only be used in C++17 and later."13#endif14 15#include <boost/math/ccmath/floor.hpp>16#include <boost/math/ccmath/abs.hpp>17#include <boost/math/ccmath/isinf.hpp>18#include <boost/math/ccmath/isnan.hpp>19 20namespace boost::math::ccmath {21 22namespace detail {23 24template <typename T>25inline constexpr T ceil_impl(T arg) noexcept26{27 T result = boost::math::ccmath::floor(arg);28 29 if(result == arg)30 {31 return result;32 }33 else34 {35 return result + 1;36 }37}38 39} // Namespace detail40 41template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true>42inline constexpr Real ceil(Real arg) noexcept43{44 if(BOOST_MATH_IS_CONSTANT_EVALUATED(arg))45 {46 return boost::math::ccmath::abs(arg) == Real(0) ? arg :47 boost::math::ccmath::isinf(arg) ? arg :48 boost::math::ccmath::isnan(arg) ? arg :49 boost::math::ccmath::detail::ceil_impl(arg);50 }51 else52 {53 using std::ceil;54 return ceil(arg);55 }56}57 58template <typename Z, std::enable_if_t<std::is_integral_v<Z>, bool> = true>59inline constexpr double ceil(Z arg) noexcept60{61 return boost::math::ccmath::ceil(static_cast<double>(arg));62}63 64inline constexpr float ceilf(float arg) noexcept65{66 return boost::math::ccmath::ceil(arg);67}68 69#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS70inline constexpr long double ceill(long double arg) noexcept71{72 return boost::math::ccmath::ceil(arg);73}74#endif75 76} // Namespaces77 78#endif // BOOST_MATH_CCMATH_CEIL_HPP79