Debian Codegraph @

third-party/boost-math/include/boost/math/ccmath/ceil.hpp

raw
1 // (C) Copyright Matt Borland 2021.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifndef BOOST_MATH_CCMATH_CEIL_HPP
7 #define BOOST_MATH_CCMATH_CEIL_HPP
8
9 #include <boost/math/ccmath/detail/config.hpp>
10
11 #ifdef BOOST_MATH_NO_CCMATH
12 #error "The header <boost/math/ceil.hpp> can only be used in C++17 and later."
13 #endif
14
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
20 namespace boost::math::ccmath {
21
22 namespace detail {
23
24 template <typename T>
25 inline constexpr T ceil_impl(T arg) noexcept
26 {
27 T result = boost::math::ccmath::floor(arg);
28
29 if(result == arg)
30 {
31 return result;
32 }
33 else
34 {
35 return result + 1;
36 }
37 }
38
39 } // Namespace detail
40
41 template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true>
42 inline constexpr Real ceil(Real arg) noexcept
43 {
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 else
52 {
53 using std::ceil;
54 return ceil(arg);
55 }
56 }
57
58 template <typename Z, std::enable_if_t<std::is_integral_v<Z>, bool> = true>
59 inline constexpr double ceil(Z arg) noexcept
60 {
61 return boost::math::ccmath::ceil(static_cast<double>(arg));
62 }
63
64 inline constexpr float ceilf(float arg) noexcept
65 {
66 return boost::math::ccmath::ceil(arg);
67 }
68
69 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
70 inline constexpr long double ceill(long double arg) noexcept
71 {
72 return boost::math::ccmath::ceil(arg);
73 }
74 #endif
75
76 } // Namespaces
77
78 #endif // BOOST_MATH_CCMATH_CEIL_HPP