]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/logaddexp_test.cpp
d0793f27addc8c3a3be4a73bcdeb801bcd7af418
1 // (C) Copyright Matt Borland 2022.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 #include "math_unit_test.hpp"
8 #include <boost/math/special_functions/logaddexp.hpp>
9 #include <boost/math/constants/constants.hpp>
11 template <typename Real
>
14 using boost::math::logaddexp
;
18 constexpr Real nan_val
= std::numeric_limits
<Real
>::quiet_NaN();
19 constexpr Real inf_val
= std::numeric_limits
<Real
>::infinity();
22 CHECK_NAN(logaddexp(nan_val
, Real(1)));
23 CHECK_NAN(logaddexp(Real(1), nan_val
));
24 CHECK_NAN(logaddexp(nan_val
, nan_val
));
27 CHECK_EQUAL(logaddexp(inf_val
, Real(1)), inf_val
);
28 CHECK_EQUAL(logaddexp(Real(1), inf_val
), inf_val
);
29 CHECK_EQUAL(logaddexp(inf_val
, inf_val
), inf_val
);
32 constexpr Real ln2
= boost::math::constants::ln_two
<Real
>();
33 CHECK_ULP_CLOSE(Real(2) + ln2
, logaddexp(Real(2), Real(2)), 1);
34 CHECK_ULP_CLOSE(Real(1e-50) + ln2
, logaddexp(Real(1e-50), Real(1e-50)), 1);
37 // https://numpy.org/doc/stable/reference/generated/numpy.logaddexp.html
38 // Calculated at higher precision using wolfram alpha
41 Real spot1
= static_cast<Real
>(exp(x1
));
42 Real spot2
= static_cast<Real
>(exp(x2
));
43 Real spot12
= logaddexp(x1
, x2
);
45 CHECK_ULP_CLOSE(log(spot1
+ spot2
), spot12
, 1);
53 return boost::math::test::report_errors();