]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/math/ccmath/trunc.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / math / ccmath / trunc.hpp
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_TRUNC_HPP
7 #define BOOST_MATH_CCMATH_TRUNC_HPP
8
9 #include <cmath>
10 #include <type_traits>
11 #include <boost/math/tools/is_constant_evaluated.hpp>
12 #include <boost/math/ccmath/abs.hpp>
13 #include <boost/math/ccmath/isinf.hpp>
14 #include <boost/math/ccmath/isnan.hpp>
15 #include <boost/math/ccmath/floor.hpp>
16 #include <boost/math/ccmath/ceil.hpp>
17
18 namespace boost::math::ccmath {
19
20 namespace detail {
21
22 template <typename T>
23 inline constexpr T trunc_impl(T arg) noexcept
24 {
25 return (arg > 0) ? boost::math::ccmath::floor(arg) : boost::math::ccmath::ceil(arg);
26 }
27
28 } // Namespace detail
29
30 template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true>
31 inline constexpr Real trunc(Real arg) noexcept
32 {
33 if(BOOST_MATH_IS_CONSTANT_EVALUATED(arg))
34 {
35 return boost::math::ccmath::abs(arg) == Real(0) ? arg :
36 boost::math::ccmath::isinf(arg) ? arg :
37 boost::math::ccmath::isnan(arg) ? arg :
38 boost::math::ccmath::detail::trunc_impl(arg);
39 }
40 else
41 {
42 using std::trunc;
43 return trunc(arg);
44 }
45 }
46
47 template <typename Z, std::enable_if_t<std::is_integral_v<Z>, bool> = true>
48 inline constexpr double trunc(Z arg) noexcept
49 {
50 return boost::math::ccmath::trunc(static_cast<double>(arg));
51 }
52
53 inline constexpr float truncf(float arg) noexcept
54 {
55 return boost::math::ccmath::trunc(arg);
56 }
57
58 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
59 inline constexpr long double truncl(long double arg) noexcept
60 {
61 return boost::math::ccmath::trunc(arg);
62 }
63 #endif
64
65 } // Namespaces
66
67 #endif // BOOST_MATH_CCMATH_TRUNC_HPP