]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/math/ccmath/div.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / math / ccmath / div.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_DIV_HPP
7 #define BOOST_MATH_CCMATH_DIV_HPP
8
9 #include <cmath>
10 #include <cstdlib>
11 #include <cinttypes>
12 #include <cstdint>
13 #include <type_traits>
14
15 namespace boost::math::ccmath {
16
17 namespace detail {
18
19 template <typename ReturnType, typename Z>
20 inline constexpr ReturnType div_impl(const Z x, const Z y) noexcept
21 {
22 // std::div_t/ldiv_t/lldiv_t/imaxdiv_t can be defined as either { Z quot; Z rem; }; or { Z rem; Z quot; };
23 // so don't use braced initialziation to guarantee compatibility
24 ReturnType ans {0, 0};
25
26 ans.quot = x / y;
27 ans.rem = x % y;
28
29 return ans;
30 }
31
32 } // Namespace detail
33
34 // Used for types other than built-ins (e.g. boost multiprecision)
35 template <typename Z>
36 struct div_t
37 {
38 Z quot;
39 Z rem;
40 };
41
42 template <typename Z>
43 inline constexpr auto div(Z x, Z y) noexcept
44 {
45 if constexpr (std::is_same_v<Z, int>)
46 {
47 return detail::div_impl<std::div_t>(x, y);
48 }
49 else if constexpr (std::is_same_v<Z, long>)
50 {
51 return detail::div_impl<std::ldiv_t>(x, y);
52 }
53 else if constexpr (std::is_same_v<Z, long long>)
54 {
55 return detail::div_impl<std::lldiv_t>(x, y);
56 }
57 else if constexpr (std::is_same_v<Z, std::intmax_t>)
58 {
59 return detail::div_impl<std::imaxdiv_t>(x, y);
60 }
61 else
62 {
63 return detail::div_impl<boost::math::ccmath::div_t<Z>>(x, y);
64 }
65 }
66
67 inline constexpr std::ldiv_t ldiv(long x, long y) noexcept
68 {
69 return detail::div_impl<std::ldiv_t>(x, y);
70 }
71
72 inline constexpr std::lldiv_t lldiv(long long x, long long y) noexcept
73 {
74 return detail::div_impl<std::lldiv_t>(x, y);
75 }
76
77 inline constexpr std::imaxdiv_t imaxdiv(std::intmax_t x, std::intmax_t y) noexcept
78 {
79 return detail::div_impl<std::imaxdiv_t>(x, y);
80 }
81
82 } // Namespaces
83
84 #endif // BOOST_MATH_CCMATH_DIV_HPP