]>
git.proxmox.com Git - ceph.git/blob - 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)
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>
15 #ifdef BOOST_HAS_FLOAT128
16 #include <boost/multiprecision/float128.hpp>
19 #if !defined(BOOST_MATH_NO_CONSTEXPR_DETECTION) && !defined(BOOST_MATH_USING_BUILTIN_CONSTANT_P)
24 if constexpr (std::numeric_limits
<T
>::has_quiet_NaN
)
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");
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))));
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));
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
>)
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());
52 // Correct promoted types
53 if constexpr (!std::is_same_v
<T
, float>)
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
)>>);
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
)>>);
70 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
74 #ifdef BOOST_HAS_FLOAT128
75 test
<boost::multiprecision::float128
>();