]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/test_dist_overloads.cpp
1 // Copyright John Maddock 2006.
2 // Copyright Paul A. Bristow 2007.
4 // Use, modification and distribution are subject to the
5 // Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt
7 // or copy at http://www.boost.org/LICENSE_1_0.txt)
9 // test_dist_overloads.cpp
11 #include <boost/math/concepts/real_concept.hpp> // for real_concept
12 #include <boost/math/distributions/normal.hpp>
13 using boost::math::normal_distribution
;
15 #define BOOST_TEST_MAIN
16 #include <boost/test/unit_test.hpp> // Boost.Test
17 #include <boost/test/tools/floating_point_comparison.hpp>
22 using std::setprecision
;
24 template <class RealType
>
25 void test_spots(RealType
)
27 // Basic sanity checks,
28 // 2 eps as a percentage:
29 RealType tolerance
= boost::math::tools::epsilon
<RealType
>() * 2 * 100;
31 cout
<< "Tolerance for type " << typeid(RealType
).name() << " is " << tolerance
<< " %" << endl
;
33 for(int i
= -4; i
<= 4; ++i
)
36 ::boost::math::cdf(normal_distribution
<RealType
>(), i
),
37 ::boost::math::cdf(normal_distribution
<RealType
>(), static_cast<RealType
>(i
)),
40 ::boost::math::pdf(normal_distribution
<RealType
>(), i
),
41 ::boost::math::pdf(normal_distribution
<RealType
>(), static_cast<RealType
>(i
)),
44 ::boost::math::cdf(complement(normal_distribution
<RealType
>(), i
)),
45 ::boost::math::cdf(complement(normal_distribution
<RealType
>(), static_cast<RealType
>(i
))),
48 ::boost::math::hazard(normal_distribution
<RealType
>(), i
),
49 ::boost::math::hazard(normal_distribution
<RealType
>(), static_cast<RealType
>(i
)),
52 ::boost::math::chf(normal_distribution
<RealType
>(), i
),
53 ::boost::math::chf(normal_distribution
<RealType
>(), static_cast<RealType
>(i
)),
56 for(float f
= 0.01f
; f
< 1; f
+= 0.01f
)
59 ::boost::math::quantile(normal_distribution
<RealType
>(), f
),
60 ::boost::math::quantile(normal_distribution
<RealType
>(), static_cast<RealType
>(f
)),
63 ::boost::math::quantile(complement(normal_distribution
<RealType
>(), f
)),
64 ::boost::math::quantile(complement(normal_distribution
<RealType
>(), static_cast<RealType
>(f
))),
67 } // template <class RealType>void test_spots(RealType)
69 BOOST_AUTO_TEST_CASE( test_main
)
71 // Basic sanity-check spot values.
72 // (Parameter value, arbitrarily zero, only communicates the floating point type).
73 test_spots(0.0F
); // Test float. OK at decdigits = 0 tolerance = 0.0001 %
74 test_spots(0.0); // Test double. OK at decdigits 7, tolerance = 1e07 %
75 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
76 test_spots(0.0L); // Test long double.
77 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
78 test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
81 std::cout
<< "<note>The long double tests have been disabled on this platform "
82 "either because the long double overloads of the usual math functions are "
83 "not available at all, or because they are too inaccurate for these tests "
84 "to pass.</note>" << std::endl
;
87 } // BOOST_AUTO_TEST_CASE( test_main )
93 Running 1 test case...
94 Tolerance for type float is 2.38419e-005 %
95 Tolerance for type double is 4.44089e-014 %
96 Tolerance for type long double is 4.44089e-014 %
97 Tolerance for type class boost::math::concepts::real_concept is 4.44089e-014 %
98 *** No errors detected