]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/ccmath_remainder_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / math / test / ccmath_remainder_test.cpp
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 #include <cmath>
7 #include <cfloat>
8 #include <cstdint>
9 #include <limits>
10 #include <type_traits>
11 #include <boost/math/ccmath/remainder.hpp>
12 #include <boost/math/ccmath/isnan.hpp>
13 #include <boost/math/ccmath/isinf.hpp>
14
15 #ifdef BOOST_HAS_FLOAT128
16 #include <boost/multiprecision/float128.hpp>
17 #endif
18
19 #if !defined(BOOST_MATH_NO_CONSTEXPR_DETECTION) && !defined(BOOST_MATH_USING_BUILTIN_CONSTANT_P)
20 template <typename T>
21 constexpr void test()
22 {
23 // Error Handling
24 if constexpr (std::numeric_limits<T>::has_quiet_NaN)
25 {
26 static_assert(boost::math::ccmath::isnan(boost::math::ccmath::remainder(std::numeric_limits<T>::quiet_NaN(), T(1))), "If x is NaN, NaN is returned");
27 static_assert(boost::math::ccmath::isnan(boost::math::ccmath::remainder(T(1), std::numeric_limits<T>::quiet_NaN())), "If y is NaN, NaN is returned");
28 }
29
30 static_assert(boost::math::ccmath::isnan(boost::math::ccmath::remainder(std::numeric_limits<T>::infinity(), T(1))));
31 static_assert(boost::math::ccmath::isnan(boost::math::ccmath::remainder(-std::numeric_limits<T>::infinity(), T(1))));
32 static_assert(boost::math::ccmath::isnan(boost::math::ccmath::remainder(T(1), T(0))));
33 static_assert(boost::math::ccmath::isnan(boost::math::ccmath::remainder(T(1), T(-0))));
34
35 // Functionality
36 static_assert(boost::math::ccmath::remainder(T(6), T(2)) == T(0));
37 static_assert(boost::math::ccmath::remainder(T(3.0/2), T(1.0) == T(3.0/2)));
38 static_assert(boost::math::ccmath::remainder(T(7.0/3), T(2.0) == T(1.0/3)));
39 static_assert(boost::math::ccmath::remainder(T(-8.0/3), T(2.0) == T(-2.0/3)));
40 static_assert(boost::math::ccmath::remainder(T(-0), T(1)) == T(-0));
41
42 // Not exact values but pulled from https://en.cppreference.com/w/cpp/numeric/math/remainder as general functionality tests so allow for some error
43 // std::is_floating_point_v excludes multi-precision types
44 if constexpr (std::is_floating_point_v<T>)
45 {
46 static_assert(boost::math::ccmath::abs(boost::math::ccmath::remainder(T(5.1l), T(3.0l)) - T(-0.9l)) < 2*std::numeric_limits<T>::epsilon());
47 static_assert(boost::math::ccmath::abs(boost::math::ccmath::remainder(T(-5.1l), T(3.0l)) - T(0.9l)) < 2*std::numeric_limits<T>::epsilon());
48 static_assert(boost::math::ccmath::abs(boost::math::ccmath::remainder(T(5.1l), T(-3.0l)) - T(-0.9l)) < 2*std::numeric_limits<T>::epsilon());
49 static_assert(boost::math::ccmath::abs(boost::math::ccmath::remainder(T(-5.1l), T(-3.0l)) - T(0.9l)) < 2*std::numeric_limits<T>::epsilon());
50 }
51
52 // Correct promoted types
53 if constexpr (!std::is_same_v<T, float>)
54 {
55 constexpr auto test_type = boost::math::ccmath::remainder(T(1), 1.0f);
56 static_assert(std::is_same_v<T, std::remove_cv_t<decltype(test_type)>>);
57 }
58 else
59 {
60 constexpr auto test_type = boost::math::ccmath::remainder(1.0f, 1);
61 static_assert(std::is_same_v<double, std::remove_cv_t<decltype(test_type)>>);
62 }
63 }
64
65 int main()
66 {
67 test<float>();
68 test<double>();
69
70 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
71 test<long double>();
72 #endif
73
74 #ifdef BOOST_HAS_FLOAT128
75 test<boost::multiprecision::float128>();
76 #endif
77
78 return 0;
79 }
80 #else
81 int main()
82 {
83 return 0;
84 }
85 #endif