]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/multiprecision/detail/functions/trunc.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / multiprecision / detail / functions / trunc.hpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright 2022 Matt Borland. Distributed under the Boost
3 // 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_MP_DETAIL_FUNCTIONS_TRUNC_HPP
7 #define BOOST_MP_DETAIL_FUNCTIONS_TRUNC_HPP
8
9 #include <cmath>
10 #include <limits>
11 #include <stdexcept>
12 #include <boost/multiprecision/detail/standalone_config.hpp>
13 #include <boost/multiprecision/detail/no_exceptions_support.hpp>
14
15 #ifdef BOOST_MP_MATH_AVAILABLE
16 #include <boost/math/special_functions/trunc.hpp>
17 #endif
18
19 namespace boost { namespace multiprecision { namespace detail {
20
21 namespace impl {
22
23 template <typename T>
24 inline T trunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
25 {
26 using std::floor;
27 using std::ceil;
28
29 return (arg > 0) ? floor(arg) : ceil(arg);
30 }
31
32 } // namespace impl
33
34 #ifdef BOOST_MP_MATH_AVAILABLE
35
36 template <typename T>
37 inline long long lltrunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
38 {
39 return boost::math::lltrunc(arg);
40 }
41
42 template <typename T>
43 inline int itrunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
44 {
45 return boost::math::itrunc(arg);
46 }
47
48 #else
49
50 template <typename T>
51 inline long long lltrunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
52 {
53 if (arg > LLONG_MAX)
54 {
55 BOOST_MP_THROW_EXCEPTION(std::domain_error("arg cannot be converted into a long long"));
56 }
57
58 return static_cast<long long>(boost::multiprecision::detail::impl::trunc(arg));
59 }
60
61 template <typename T>
62 inline int itrunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
63 {
64 if (arg > INT_MAX)
65 {
66 BOOST_MP_THROW_EXCEPTION(std::domain_error("arg cannot be converted into an int"));
67 }
68
69 return static_cast<int>(boost::multiprecision::detail::impl::trunc(arg));
70 }
71
72 #endif
73
74 }}} // Namespaces
75
76 #endif // BOOST_MP_DETAIL_FUNCTIONS_TRUNC_HPP