]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright Paul Bristow 2007, 2011. |
2 | // Copyright John Maddock 2006, 2011. | |
3 | ||
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) | |
8 | ||
7c673cae FG |
9 | // Check values of constants are drawn from an independent source, or calculated. |
10 | // Both must be at long double precision for the most precise compilers floating-point implementation. | |
11 | // So all values use static_cast<RealType>() of values at least 40 decimal digits | |
12 | // and that have suffix L to ensure floating-point type is long double. | |
13 | ||
14 | // Steve Moshier's command interpreter V1.3 100 digits calculator used for some values. | |
15 | ||
16 | #ifdef _MSC_VER | |
17 | # pragma warning(disable : 4127) // conditional expression is constant. | |
18 | #endif | |
20effc67 | 19 | #include "math_unit_test.hpp" |
7c673cae | 20 | #include <boost/math/concepts/real_concept.hpp> // for real_concept |
7c673cae | 21 | #include <boost/math/constants/constants.hpp> |
7c673cae | 22 | #include <boost/utility/enable_if.hpp> |
20effc67 TL |
23 | #include <boost/multiprecision/cpp_bin_float.hpp> |
24 | #ifdef BOOST_MATH_HAS_FLOAT128 | |
25 | #include <boost/multiprecision/float128.hpp> | |
26 | #endif | |
7c673cae | 27 | |
20effc67 TL |
28 | #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900) |
29 | #include <boost/math/tools/agm.hpp> | |
7c673cae | 30 | // Check at compile time that the construction method for constants of type float, is "construct from a float", or "construct from a double", ... |
20effc67 TL |
31 | static_assert((boost::is_same<boost::math::constants::construction_traits<float, boost::math::policies::policy<> >::type, boost::integral_constant<int, boost::math::constants::construct_from_float> >::value), "Need to be able to construct from float"); |
32 | static_assert((boost::is_same<boost::math::constants::construction_traits<double, boost::math::policies::policy<> >::type, boost::integral_constant<int, boost::math::constants::construct_from_double> >::value), "Need to be able to construct from double"); | |
33 | static_assert((boost::is_same<boost::math::constants::construction_traits<long double, boost::math::policies::policy<> >::type, boost::integral_constant<int, (sizeof(double) == sizeof(long double) ? boost::math::constants::construct_from_double : boost::math::constants::construct_from_long_double)> >::value), "Need to be able to construct from long double"); | |
34 | static_assert((boost::is_same<boost::math::constants::construction_traits<boost::math::concepts::real_concept, boost::math::policies::policy<> >::type, boost::integral_constant<int, 0> >::value), "Need to be able to construct from real_concept"); | |
7c673cae FG |
35 | |
36 | // Policy to set precision at maximum possible using long double. | |
37 | typedef boost::math::policies::policy<boost::math::policies::digits2<std::numeric_limits<long double>::digits> > real_concept_policy_1; | |
38 | // Policy with precision +2 (could be any reasonable value), | |
39 | // forces the precision of the policy to be greater than | |
40 | // that of a long double, and therefore triggers different code (construct from string). | |
41 | #ifdef BOOST_MATH_USE_FLOAT128 | |
42 | typedef boost::math::policies::policy<boost::math::policies::digits2<115> > real_concept_policy_2; | |
43 | #else | |
44 | typedef boost::math::policies::policy<boost::math::policies::digits2<std::numeric_limits<long double>::digits + 2> > real_concept_policy_2; | |
45 | #endif | |
46 | // Policy with precision greater than the string representations, forces computation of values (i.e. different code path): | |
47 | typedef boost::math::policies::policy<boost::math::policies::digits2<400> > real_concept_policy_3; | |
48 | ||
20effc67 TL |
49 | static_assert((boost::is_same<boost::math::constants::construction_traits<boost::math::concepts::real_concept, real_concept_policy_1 >::type, boost::integral_constant<int, (sizeof(double) == sizeof(long double) ? boost::math::constants::construct_from_double : boost::math::constants::construct_from_long_double) > >::value), "Need to be able to construct from long double"); |
50 | static_assert((boost::is_same<boost::math::constants::construction_traits<boost::math::concepts::real_concept, real_concept_policy_2 >::type, boost::integral_constant<int, boost::math::constants::construct_from_string> >::value), "Need to be able to construct integer from string"); | |
51 | static_assert((boost::math::constants::construction_traits<boost::math::concepts::real_concept, real_concept_policy_3>::type::value >= 5), "Nee 5 digits"); | |
52 | #endif // C++11 | |
7c673cae FG |
53 | |
54 | // We need to declare a conceptual type whose precision is unknown at | |
55 | // compile time, and is so enormous when checked at runtime, | |
56 | // that we're forced to calculate the values of the constants ourselves. | |
57 | ||
58 | namespace boost{ namespace math{ namespace concepts{ | |
59 | ||
60 | class big_real_concept : public real_concept | |
61 | { | |
62 | public: | |
63 | big_real_concept() {} | |
64 | template <class T> | |
65 | big_real_concept(const T& t, typename enable_if<is_convertible<T, real_concept> >::type* = 0) : real_concept(t) {} | |
66 | }; | |
67 | ||
68 | inline int itrunc(const big_real_concept& val) | |
69 | { | |
70 | BOOST_MATH_STD_USING | |
71 | return itrunc(val.value()); | |
72 | } | |
73 | ||
74 | } | |
75 | namespace tools{ | |
76 | ||
77 | template <> | |
78 | inline BOOST_MATH_CONSTEXPR int digits<concepts::big_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T)) BOOST_NOEXCEPT | |
79 | { | |
80 | return 2 * boost::math::constants::max_string_digits; | |
81 | } | |
82 | ||
83 | }}} | |
84 | ||
85 | template <class RealType> | |
86 | void test_spots(RealType) | |
87 | { | |
88 | // Basic sanity checks for constants, | |
89 | // where template parameter RealType can be float, double, long double, | |
90 | // or real_concept, a prototype for user-defined floating-point types. | |
91 | ||
92 | // Parameter RealType is only used to communicate the RealType, | |
20effc67 | 93 | // and is an arbitrary zero for all tests. |
7c673cae | 94 | |
20effc67 | 95 | //typedef typename boost::math::constants::construction_traits<RealType, boost::math::policies::policy<> >::type construction_type; |
7c673cae FG |
96 | using namespace boost::math::constants; |
97 | BOOST_MATH_STD_USING | |
98 | ||
20effc67 TL |
99 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L, pi<RealType>(), 2); |
100 | CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L), root_pi<RealType>(), 2); | |
101 | CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L/2), root_half_pi<RealType>(), 2); | |
102 | CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L * 2), root_two_pi<RealType>(), 2); | |
103 | CHECK_ULP_CLOSE(sqrt(log(4.0L)), root_ln_four<RealType>(), 2); | |
104 | CHECK_ULP_CLOSE(2.71828182845904523536028747135266249775724709369995L, e<RealType>(), 2); | |
105 | CHECK_ULP_CLOSE(0.5L, half<RealType>(), 2); | |
106 | CHECK_ULP_CLOSE(0.57721566490153286060651209008240243104259335L, euler<RealType>(), 2); | |
107 | CHECK_ULP_CLOSE(sqrt(2.0L), root_two<RealType>(), 2); | |
108 | CHECK_ULP_CLOSE(log(2.0L), ln_two<RealType>(), 2); | |
109 | CHECK_ULP_CLOSE(log(10.0L), ln_ten<RealType>(), 2); | |
110 | CHECK_ULP_CLOSE(log(log(2.0L)), ln_ln_two<RealType>(), 2); | |
111 | ||
112 | CHECK_ULP_CLOSE(static_cast<long double>(1)/3, third<RealType>(), 2); | |
113 | CHECK_ULP_CLOSE(static_cast<long double>(2)/3, twothirds<RealType>(), 2); | |
114 | CHECK_ULP_CLOSE(0.14159265358979323846264338327950288419716939937510L, pi_minus_three<RealType>(), 2); | |
115 | CHECK_ULP_CLOSE(4.L - 3.14159265358979323846264338327950288419716939937510L, four_minus_pi<RealType>(), 2); | |
7c673cae | 116 | #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS |
20effc67 TL |
117 | CHECK_ULP_CLOSE(pow((3.14159265358979323846264338327950288419716939937510L), 2.71828182845904523536028747135266249775724709369995L), pi_pow_e<RealType>(), 2); |
118 | CHECK_ULP_CLOSE(pow((3.14159265358979323846264338327950288419716939937510L), 0.33333333333333333333333333333333333333333333333333L), cbrt_pi<RealType>(), 2); | |
119 | CHECK_ULP_CLOSE(exp(-0.5L), exp_minus_half<RealType>(), 2); | |
120 | CHECK_ULP_CLOSE(pow(2.71828182845904523536028747135266249775724709369995L, 3.14159265358979323846264338327950288419716939937510L), e_pow_pi<RealType>(), 2); | |
7c673cae FG |
121 | |
122 | ||
123 | #else // Only double, so no suffix L. | |
20effc67 TL |
124 | CHECK_ULP_CLOSE(pow((3.14159265358979323846264338327950288419716939937510), 2.71828182845904523536028747135266249775724709369995), pi_pow_e<RealType>(), 2); |
125 | CHECK_ULP_CLOSE(pow((3.14159265358979323846264338327950288419716939937510), 0.33333333333333333333333333333333333333333333333333), cbrt_pi<RealType>(), 2); | |
126 | CHECK_ULP_CLOSE(exp(-0.5), exp_minus_half<RealType>(), 2); | |
7c673cae FG |
127 | #endif |
128 | // Rational fractions. | |
20effc67 TL |
129 | CHECK_ULP_CLOSE(0.333333333333333333333333333333333333333L, third<RealType>(), 2); |
130 | CHECK_ULP_CLOSE(0.666666666666666666666666666666666666667L, two_thirds<RealType>(), 2); | |
131 | CHECK_ULP_CLOSE(0.75L, three_quarters<RealType>(), 2); | |
132 | CHECK_ULP_CLOSE(0.1666666666666666666666666666666666666667L, sixth<RealType>(), 2); | |
92f5a8d4 | 133 | |
7c673cae | 134 | // Two and related. |
20effc67 TL |
135 | CHECK_ULP_CLOSE(sqrt(2.L), root_two<RealType>(), 2); |
136 | CHECK_ULP_CLOSE(sqrt(3.L), root_three<RealType>(), 2); | |
137 | CHECK_ULP_CLOSE(sqrt(2.L)/2, half_root_two<RealType>(), 2); | |
138 | CHECK_ULP_CLOSE(log(2.L), ln_two<RealType>(), 2); | |
139 | CHECK_ULP_CLOSE(log(log(2.0L)), ln_ln_two<RealType>(), 2); | |
140 | CHECK_ULP_CLOSE(sqrt(log(4.0L)), root_ln_four<RealType>(), 2); | |
141 | CHECK_ULP_CLOSE(1/sqrt(2.0L), one_div_root_two<RealType>(), 2); | |
7c673cae FG |
142 | |
143 | // pi. | |
20effc67 TL |
144 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L, pi<RealType>(), 2); |
145 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L/2, half_pi<RealType>(), 2); | |
146 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L/4, quarter_pi<RealType>(), 2); | |
147 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L/3, third_pi<RealType>(), 2); | |
148 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L/4, quarter_pi<RealType>(), 2); | |
149 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L/6, sixth_pi<RealType>(), 2); | |
150 | CHECK_ULP_CLOSE(2 * 3.14159265358979323846264338327950288419716939937510L, two_pi<RealType>(), 2); | |
151 | CHECK_ULP_CLOSE(3 * 3.14159265358979323846264338327950288419716939937510L / 4, three_quarters_pi<RealType>(), 2); | |
152 | CHECK_ULP_CLOSE(4 * 3.14159265358979323846264338327950288419716939937510L / 3, four_thirds_pi<RealType>(), 2); | |
153 | CHECK_ULP_CLOSE(1 / (3.14159265358979323846264338327950288419716939937510L), one_div_pi<RealType>(), 2); | |
154 | CHECK_ULP_CLOSE(2 / (3.14159265358979323846264338327950288419716939937510L), two_div_pi<RealType>(), 2); | |
155 | CHECK_ULP_CLOSE(1 / (2 * 3.14159265358979323846264338327950288419716939937510L), one_div_two_pi<RealType>(), 2); | |
156 | CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L), root_pi<RealType>(), 2); | |
157 | CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L / 2), root_half_pi<RealType>(), 2); | |
158 | CHECK_ULP_CLOSE(sqrt(2 * 3.14159265358979323846264338327950288419716939937510L), root_two_pi<RealType>(), 2); | |
159 | CHECK_ULP_CLOSE(1 / sqrt(3.14159265358979323846264338327950288419716939937510L), one_div_root_pi<RealType>(), 2); | |
160 | CHECK_ULP_CLOSE(2 / sqrt(3.14159265358979323846264338327950288419716939937510L), two_div_root_pi<RealType>(), 2); | |
161 | CHECK_ULP_CLOSE(1 / sqrt(2 * 3.14159265358979323846264338327950288419716939937510L), one_div_root_two_pi<RealType>(), 2); | |
162 | CHECK_ULP_CLOSE(sqrt(1. / 3.14159265358979323846264338327950288419716939937510L), root_one_div_pi<RealType>(), 2); | |
163 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L - 3.L, pi_minus_three<RealType>(), 4 * 4 ); // 4 * 2 because of cancellation loss. | |
164 | CHECK_ULP_CLOSE(4.L - 3.14159265358979323846264338327950288419716939937510L, four_minus_pi<RealType>(), 4 ); | |
7c673cae | 165 | // |
20effc67 TL |
166 | CHECK_ULP_CLOSE(pow((3.14159265358979323846264338327950288419716939937510L), 2.71828182845904523536028747135266249775724709369995L), pi_pow_e<RealType>(), 2); // See above. |
167 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L, pi_sqr<RealType>(), 2); // See above. | |
168 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L/6, pi_sqr_div_six<RealType>(), 2); // See above. | |
169 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L, pi_cubed<RealType>(), 2); // See above. | |
7c673cae | 170 | |
20effc67 TL |
171 | // CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L, cbrt_pi<RealType>(), 2); // See above. |
172 | CHECK_ULP_CLOSE(cbrt_pi<RealType>() * cbrt_pi<RealType>() * cbrt_pi<RealType>(), pi<RealType>(), 2); | |
173 | CHECK_ULP_CLOSE((1)/cbrt_pi<RealType>(), one_div_cbrt_pi<RealType>(), 2); | |
7c673cae FG |
174 | |
175 | // Euler | |
20effc67 TL |
176 | CHECK_ULP_CLOSE(2.71828182845904523536028747135266249775724709369995L, e<RealType>(), 2); |
177 | //CHECK_ULP_CLOSE(exp(-0.5L), exp_minus_half<RealType>(), 2); // See above. | |
178 | CHECK_ULP_CLOSE(exp(-1.L), exp_minus_one<RealType>(), 2); | |
179 | CHECK_ULP_CLOSE(pow(e<RealType>(), pi<RealType>()), e_pow_pi<RealType>(), 2); // See also above. | |
180 | CHECK_ULP_CLOSE(sqrt(e<RealType>()), root_e<RealType>(), 2); | |
181 | CHECK_ULP_CLOSE(log10(e<RealType>()), log10_e<RealType>(), 2); | |
182 | CHECK_ULP_CLOSE(1/log10(e<RealType>()), one_div_log10_e<RealType>(), 2); | |
183 | CHECK_ULP_CLOSE((1/ln_two<RealType>()), log2_e<RealType>(), 2); | |
7c673cae | 184 | |
f67539c2 | 185 | // Trigonometric |
20effc67 TL |
186 | CHECK_ULP_CLOSE(pi<RealType>()/180, degree<RealType>(), 2); |
187 | CHECK_ULP_CLOSE(180 / pi<RealType>(), radian<RealType>(), 2); | |
188 | CHECK_ULP_CLOSE(sin(1.L), sin_one<RealType>(), 2); | |
189 | CHECK_ULP_CLOSE(cos(1.L), cos_one<RealType>(), 2); | |
190 | CHECK_ULP_CLOSE(sinh(1.L), sinh_one<RealType>(), 2); | |
191 | CHECK_ULP_CLOSE(cosh(1.L), cosh_one<RealType>(), 2); | |
7c673cae FG |
192 | |
193 | // Phi | |
20effc67 TL |
194 | CHECK_ULP_CLOSE((1.L + sqrt(5.L)) /2, phi<RealType>(), 2); |
195 | CHECK_ULP_CLOSE(log((1.L + sqrt(5.L)) /2), ln_phi<RealType>(), 2); | |
196 | CHECK_ULP_CLOSE(1.L / log((1.L + sqrt(5.L)) /2), one_div_ln_phi<RealType>(), 2); | |
7c673cae FG |
197 | |
198 | //Euler's Gamma | |
20effc67 TL |
199 | CHECK_ULP_CLOSE(0.57721566490153286060651209008240243104215933593992L, euler<RealType>(), 2); // (sequence A001620 in OEIS). |
200 | CHECK_ULP_CLOSE(1.L/ 0.57721566490153286060651209008240243104215933593992L, one_div_euler<RealType>(), 2); // (from sequence A001620 in OEIS). | |
201 | CHECK_ULP_CLOSE(0.57721566490153286060651209008240243104215933593992L * 0.57721566490153286060651209008240243104215933593992L, euler_sqr<RealType>(), 2); // (from sequence A001620 in OEIS). | |
7c673cae FG |
202 | |
203 | // Misc | |
20effc67 TL |
204 | CHECK_ULP_CLOSE(1.644934066848226436472415166646025189218949901206L, zeta_two<RealType>(), 2); // A013661 as a constant (usually base 10) in OEIS. |
205 | CHECK_ULP_CLOSE(1.20205690315959428539973816151144999076498629234049888179227L, zeta_three<RealType>(), 2); // (sequence A002117 in OEIS) | |
206 | CHECK_ULP_CLOSE(.91596559417721901505460351493238411077414937428167213L, catalan<RealType>(), 2); // A006752 as a constant in OEIS. | |
207 | CHECK_ULP_CLOSE(1.1395470994046486574927930193898461120875997958365518247216557100852480077060706857071875468869385150L, extreme_value_skewness<RealType>(), 2); // Mathematica: N[12 Sqrt[6] Zeta[3]/Pi^3, 1101] | |
208 | CHECK_ULP_CLOSE(0.6311106578189371381918993515442277798440422031347194976580945856929268196174737254599050270325373067L, rayleigh_skewness<RealType>(), 2); // Mathematica: N[2 Sqrt[Pi] (Pi - 3)/((4 - Pi)^(3/2)), 1100] | |
209 | CHECK_ULP_CLOSE(2.450893006876380628486604106197544154e-01L, rayleigh_kurtosis_excess<RealType>(), 4 * 2); | |
210 | CHECK_ULP_CLOSE(2.68545200106530644530971483548179569382038229399446295305115234555721885953715200280114117493184769799515L, khinchin<RealType>(), 4 ); // A002210 as a constant https://oeis.org/A002210/constant | |
211 | CHECK_ULP_CLOSE(1.2824271291006226368753425688697917277676889273250011L, glaisher<RealType>(), 4 ); // https://oeis.org/A074962/constant | |
7c673cae FG |
212 | |
213 | // | |
214 | // Last of all come the test cases that behave differently if we're calculating the constants on the fly: | |
215 | // | |
216 | if(boost::math::tools::digits<RealType>() > boost::math::constants::max_string_digits) | |
217 | { | |
20effc67 TL |
218 | // This suffers from cancellation error, so increased 4: |
219 | CHECK_ULP_CLOSE(static_cast<RealType>(4. - 3.14159265358979323846264338327950288419716939937510L), four_minus_pi<RealType>(), 4 * 3); | |
220 | CHECK_ULP_CLOSE(static_cast<RealType>(0.14159265358979323846264338327950288419716939937510L), pi_minus_three<RealType>(), 4 * 3); | |
7c673cae FG |
221 | } |
222 | else | |
223 | { | |
20effc67 TL |
224 | CHECK_ULP_CLOSE(static_cast<RealType>(4. - 3.14159265358979323846264338327950288419716939937510L), four_minus_pi<RealType>(), 2); |
225 | CHECK_ULP_CLOSE(static_cast<RealType>(0.14159265358979323846264338327950288419716939937510L), pi_minus_three<RealType>(), 2); | |
7c673cae FG |
226 | } |
227 | } // template <class RealType>void test_spots(RealType) | |
228 | ||
229 | void test_float_spots() | |
230 | { | |
231 | // Basic sanity checks for constants in boost::math::float_constants:: | |
232 | // for example: boost::math::float_constants::pi | |
233 | // (rather than boost::math::constants::pi<float>() ). | |
7c673cae FG |
234 | using namespace boost::math::float_constants; |
235 | BOOST_MATH_STD_USING | |
236 | ||
20effc67 TL |
237 | CHECK_ULP_CLOSE(static_cast<float>(3.14159265358979323846264338327950288419716939937510F), pi, 2); |
238 | CHECK_ULP_CLOSE(static_cast<float>(sqrt(3.14159265358979323846264338327950288419716939937510F)), root_pi, 2); | |
239 | CHECK_ULP_CLOSE(static_cast<float>(sqrt(3.14159265358979323846264338327950288419716939937510F/2)), root_half_pi, 2); | |
240 | CHECK_ULP_CLOSE(static_cast<float>(sqrt(3.14159265358979323846264338327950288419716939937510F * 2)), root_two_pi, 2); | |
241 | CHECK_ULP_CLOSE(static_cast<float>(sqrt(log(4.0F))), root_ln_four, 2); | |
242 | CHECK_ULP_CLOSE(static_cast<float>(2.71828182845904523536028747135266249775724709369995F), e, 2); | |
243 | CHECK_ULP_CLOSE(static_cast<float>(0.5), half, 2); | |
244 | CHECK_ULP_CLOSE(static_cast<float>(0.57721566490153286060651209008240243104259335F), euler, 2); | |
245 | CHECK_ULP_CLOSE(static_cast<float>(sqrt(2.0F)), root_two, 2); | |
246 | CHECK_ULP_CLOSE(static_cast<float>(log(2.0F)), ln_two, 2); | |
247 | CHECK_ULP_CLOSE(static_cast<float>(log(log(2.0F))), ln_ln_two, 2); | |
248 | CHECK_ULP_CLOSE(static_cast<float>(1)/3, third, 2); | |
249 | CHECK_ULP_CLOSE(static_cast<float>(2)/3, twothirds, 2); | |
250 | CHECK_ULP_CLOSE(static_cast<float>(0.14159265358979323846264338327950288419716939937510F), pi_minus_three, 2); | |
251 | CHECK_ULP_CLOSE(static_cast<float>(4.F - 3.14159265358979323846264338327950288419716939937510F), four_minus_pi, 2); | |
7c673cae | 252 | #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS |
20effc67 TL |
253 | CHECK_ULP_CLOSE(static_cast<float>(pow((3.14159265358979323846264338327950288419716939937510F), 2.71828182845904523536028747135266249775724709369995F)), pi_pow_e, 2); |
254 | CHECK_ULP_CLOSE(static_cast<float>(pow((3.14159265358979323846264338327950288419716939937510F), 0.33333333333333333333333333333333333333333333333333F)), cbrt_pi, 2); | |
255 | CHECK_ULP_CLOSE(static_cast<float>(exp(-0.5F)), exp_minus_half, 2); | |
256 | CHECK_ULP_CLOSE(static_cast<float>(pow(2.71828182845904523536028747135266249775724709369995F, 3.14159265358979323846264338327950288419716939937510F)), e_pow_pi, 2); | |
7c673cae FG |
257 | |
258 | ||
259 | #else // Only double, so no suffix F. | |
20effc67 TL |
260 | CHECK_ULP_CLOSE(static_cast<float>(pow((3.14159265358979323846264338327950288419716939937510), 2.71828182845904523536028747135266249775724709369995)), pi_pow_e, 2); |
261 | CHECK_ULP_CLOSE(static_cast<float>(pow((3.14159265358979323846264338327950288419716939937510), 0.33333333333333333333333333333333333333333333333333)), cbrt_pi, 2); | |
262 | CHECK_ULP_CLOSE(static_cast<float>(exp(-0.5)), exp_minus_half, 2); | |
7c673cae FG |
263 | #endif |
264 | // Rational fractions. | |
20effc67 TL |
265 | CHECK_ULP_CLOSE(static_cast<float>(0.333333333333333333333333333333333333333F), third, 2); |
266 | CHECK_ULP_CLOSE(static_cast<float>(0.666666666666666666666666666666666666667F), two_thirds, 2); | |
267 | CHECK_ULP_CLOSE(static_cast<float>(0.75F), three_quarters, 2); | |
7c673cae | 268 | // Two and related. |
20effc67 TL |
269 | CHECK_ULP_CLOSE(static_cast<float>(sqrt(2.F)), root_two, 2); |
270 | CHECK_ULP_CLOSE(static_cast<float>(sqrt(3.F)), root_three, 2); | |
271 | CHECK_ULP_CLOSE(static_cast<float>(sqrt(2.F)/2), half_root_two, 2); | |
272 | CHECK_ULP_CLOSE(static_cast<float>(log(2.F)), ln_two, 2); | |
273 | CHECK_ULP_CLOSE(static_cast<float>(log(log(2.0F))), ln_ln_two, 2); | |
274 | CHECK_ULP_CLOSE(static_cast<float>(sqrt(log(4.0F))), root_ln_four, 2); | |
275 | CHECK_ULP_CLOSE(static_cast<float>(1/sqrt(2.0F)), one_div_root_two, 2); | |
7c673cae FG |
276 | |
277 | // pi. | |
20effc67 TL |
278 | CHECK_ULP_CLOSE(static_cast<float>(3.14159265358979323846264338327950288419716939937510F), pi, 2); |
279 | CHECK_ULP_CLOSE(static_cast<float>(3.14159265358979323846264338327950288419716939937510F/2), half_pi, 2); | |
280 | CHECK_ULP_CLOSE(static_cast<float>(3.14159265358979323846264338327950288419716939937510F/4), quarter_pi, 2); | |
281 | CHECK_ULP_CLOSE(static_cast<float>(3.14159265358979323846264338327950288419716939937510F/3), third_pi, 2); | |
282 | CHECK_ULP_CLOSE(static_cast<float>(3.14159265358979323846264338327950288419716939937510F/6), sixth_pi, 2); | |
283 | CHECK_ULP_CLOSE(static_cast<float>(2 * 3.14159265358979323846264338327950288419716939937510F), two_pi, 2); | |
284 | CHECK_ULP_CLOSE(static_cast<float>(3 * 3.14159265358979323846264338327950288419716939937510F / 4), three_quarters_pi, 2); | |
285 | CHECK_ULP_CLOSE(static_cast<float>(4 * 3.14159265358979323846264338327950288419716939937510F / 3), four_thirds_pi, 2); | |
286 | CHECK_ULP_CLOSE(static_cast<float>(1 / (3.14159265358979323846264338327950288419716939937510F)), one_div_pi, 2); | |
287 | CHECK_ULP_CLOSE(static_cast<float>(2 / (3.14159265358979323846264338327950288419716939937510F)), two_div_pi, 2); | |
288 | CHECK_ULP_CLOSE(static_cast<float>(1 / (2 * 3.14159265358979323846264338327950288419716939937510F)), one_div_two_pi, 2); | |
289 | CHECK_ULP_CLOSE(static_cast<float>(sqrt(3.14159265358979323846264338327950288419716939937510F)), root_pi, 2); | |
290 | CHECK_ULP_CLOSE(static_cast<float>(sqrt(3.14159265358979323846264338327950288419716939937510F / 2)), root_half_pi, 2); | |
291 | CHECK_ULP_CLOSE(static_cast<float>(sqrt(2 * 3.14159265358979323846264338327950288419716939937510F)), root_two_pi, 2); | |
292 | CHECK_ULP_CLOSE(static_cast<float>(1 / sqrt(3.14159265358979323846264338327950288419716939937510F)), one_div_root_pi, 2); | |
293 | CHECK_ULP_CLOSE(static_cast<float>(2 / sqrt(3.14159265358979323846264338327950288419716939937510F)), two_div_root_pi, 2); | |
294 | CHECK_ULP_CLOSE(static_cast<float>(1 / sqrt(2 * 3.14159265358979323846264338327950288419716939937510F)), one_div_root_two_pi, 2); | |
295 | CHECK_ULP_CLOSE(static_cast<float>(sqrt(1. / 3.14159265358979323846264338327950288419716939937510F)), root_one_div_pi, 2); | |
296 | CHECK_ULP_CLOSE(static_cast<float>(3.14159265358979323846264338327950288419716939937510L - 3.L), pi_minus_three, 4 * 2 ); // 4 * 2 because of cancellation loss. | |
297 | CHECK_ULP_CLOSE(static_cast<float>(4.L - 3.14159265358979323846264338327950288419716939937510L), four_minus_pi, 4 ); | |
7c673cae | 298 | // |
20effc67 TL |
299 | CHECK_ULP_CLOSE(static_cast<float>(pow((3.14159265358979323846264338327950288419716939937510F), 2.71828182845904523536028747135266249775724709369995F)), pi_pow_e, 2); // See above. |
300 | CHECK_ULP_CLOSE(static_cast<float>(3.14159265358979323846264338327950288419716939937510F * 3.14159265358979323846264338327950288419716939937510F), pi_sqr, 2); // See above. | |
301 | CHECK_ULP_CLOSE(static_cast<float>(3.14159265358979323846264338327950288419716939937510F * 3.14159265358979323846264338327950288419716939937510F/6), pi_sqr_div_six, 2); // See above. | |
302 | CHECK_ULP_CLOSE(static_cast<float>(3.14159265358979323846264338327950288419716939937510F * 3.14159265358979323846264338327950288419716939937510F * 3.14159265358979323846264338327950288419716939937510F), pi_cubed, 2); // See above. | |
7c673cae | 303 | |
20effc67 TL |
304 | // CHECK_ULP_CLOSE(static_cast<float>(3.14159265358979323846264338327950288419716939937510F * 3.14159265358979323846264338327950288419716939937510F), cbrt_pi, 2); // See above. |
305 | CHECK_ULP_CLOSE(cbrt_pi * cbrt_pi * cbrt_pi, pi, 2); | |
306 | CHECK_ULP_CLOSE((static_cast<float>(1)/cbrt_pi), one_div_cbrt_pi, 2); | |
7c673cae FG |
307 | |
308 | // Euler | |
20effc67 | 309 | CHECK_ULP_CLOSE(static_cast<float>(2.71828182845904523536028747135266249775724709369995F), e, 2); |
7c673cae | 310 | |
20effc67 TL |
311 | //CHECK_ULP_CLOSE(static_cast<float>(exp(-0.5F)), exp_minus_half, 2); // See above. |
312 | CHECK_ULP_CLOSE(pow(e, pi), e_pow_pi, 2); // See also above. | |
313 | CHECK_ULP_CLOSE(sqrt(e), root_e, 2); | |
314 | CHECK_ULP_CLOSE(log10(e), log10_e, 2); | |
315 | CHECK_ULP_CLOSE(static_cast<float>(1)/log10(e), one_div_log10_e, 2); | |
7c673cae | 316 | |
f67539c2 | 317 | // Trigonometric |
20effc67 TL |
318 | CHECK_ULP_CLOSE(pi/180, degree, 2); |
319 | CHECK_ULP_CLOSE(180 / pi, radian, 2); | |
320 | CHECK_ULP_CLOSE(sin(1.F), sin_one, 2); | |
321 | CHECK_ULP_CLOSE(cos(1.F), cos_one, 2); | |
322 | CHECK_ULP_CLOSE(sinh(1.F), sinh_one, 2); | |
323 | CHECK_ULP_CLOSE(cosh(1.F), cosh_one, 2); | |
7c673cae FG |
324 | |
325 | // Phi | |
20effc67 TL |
326 | CHECK_ULP_CLOSE((1.F + sqrt(5.F)) /2, phi, 2); |
327 | CHECK_ULP_CLOSE(log((1.F + sqrt(5.F)) /2), ln_phi, 2); | |
328 | CHECK_ULP_CLOSE(1.F / log((1.F + sqrt(5.F)) /2), one_div_ln_phi, 2); | |
7c673cae FG |
329 | |
330 | // Euler's Gamma | |
20effc67 TL |
331 | CHECK_ULP_CLOSE(0.57721566490153286060651209008240243104215933593992F, euler, 2); // (sequence A001620 in OEIS). |
332 | CHECK_ULP_CLOSE(1.F/ 0.57721566490153286060651209008240243104215933593992F, one_div_euler, 2); // (from sequence A001620 in OEIS). | |
333 | CHECK_ULP_CLOSE(0.57721566490153286060651209008240243104215933593992F * 0.57721566490153286060651209008240243104215933593992F, euler_sqr, 2); // (from sequence A001620 in OEIS). | |
7c673cae FG |
334 | |
335 | // Misc | |
20effc67 TL |
336 | CHECK_ULP_CLOSE(1.644934066848226436472415166646025189218949901206F, zeta_two, 2); // A013661 as a constant (usually base 10) in OEIS. |
337 | CHECK_ULP_CLOSE(1.20205690315959428539973816151144999076498629234049888179227F, zeta_three, 2); // (sequence A002117 in OEIS) | |
338 | CHECK_ULP_CLOSE(.91596559417721901505460351493238411077414937428167213F, catalan, 2); // A006752 as a constant in OEIS. | |
339 | CHECK_ULP_CLOSE(1.1395470994046486574927930193898461120875997958365518247216557100852480077060706857071875468869385150F, extreme_value_skewness, 2); // Mathematica: N[12 Sqrt[6] Zeta[3]/Pi^3, 1101] | |
340 | CHECK_ULP_CLOSE(0.6311106578189371381918993515442277798440422031347194976580945856929268196174737254599050270325373067F, rayleigh_skewness, 2); // Mathematica: N[2 Sqrt[Pi] (Pi - 3)/((4 - Pi)^(3/2)), 1100] | |
341 | CHECK_ULP_CLOSE(2.450893006876380628486604106197544154e-01F, rayleigh_kurtosis_excess, 2); | |
342 | CHECK_ULP_CLOSE(2.68545200106530644530971483548179569382038229399446295305115234555721885953715200280114117493184769799515F, khinchin, 4 ); // A002210 as a constant https://oeis.org/A002210/constant | |
343 | CHECK_ULP_CLOSE(1.2824271291006226368753425688697917277676889273250011F, glaisher, 4 ); // https://oeis.org/A074962/constant | |
344 | CHECK_ULP_CLOSE(4.66920160910299067185320382046620161725F, first_feigenbaum, 1); | |
7c673cae FG |
345 | } // template <class RealType>void test_spots(RealType) |
346 | ||
347 | void test_double_spots() | |
348 | { | |
349 | // Basic sanity checks for constants in boost::math::double_constants:: | |
350 | // for example: boost::math::double_constants::pi | |
351 | // (rather than boost::math::constants::pi<double>() ). | |
7c673cae FG |
352 | using namespace boost::math::double_constants; |
353 | BOOST_MATH_STD_USING | |
354 | ||
20effc67 TL |
355 | CHECK_ULP_CLOSE(static_cast<double>(3.14159265358979323846264338327950288419716939937510), pi, 2); |
356 | CHECK_ULP_CLOSE(static_cast<double>(sqrt(3.14159265358979323846264338327950288419716939937510)), root_pi, 2); | |
357 | CHECK_ULP_CLOSE(static_cast<double>(sqrt(3.14159265358979323846264338327950288419716939937510/2)), root_half_pi, 2); | |
358 | CHECK_ULP_CLOSE(static_cast<double>(sqrt(3.14159265358979323846264338327950288419716939937510 * 2)), root_two_pi, 2); | |
359 | CHECK_ULP_CLOSE(static_cast<double>(sqrt(log(4.0))), root_ln_four, 2); | |
360 | CHECK_ULP_CLOSE(static_cast<double>(2.71828182845904523536028747135266249775724709369995), e, 2); | |
361 | CHECK_ULP_CLOSE(static_cast<double>(0.5), half, 2); | |
362 | CHECK_ULP_CLOSE(static_cast<double>(0.57721566490153286060651209008240243104259335), euler, 2); | |
363 | CHECK_ULP_CLOSE(static_cast<double>(sqrt(2.0)), root_two, 2); | |
364 | CHECK_ULP_CLOSE(static_cast<double>(log(2.0)), ln_two, 2); | |
365 | CHECK_ULP_CLOSE(static_cast<double>(log(log(2.0))), ln_ln_two, 2); | |
366 | CHECK_ULP_CLOSE(static_cast<double>(1)/3, third, 2); | |
367 | CHECK_ULP_CLOSE(static_cast<double>(2)/3, twothirds, 2); | |
368 | CHECK_ULP_CLOSE(static_cast<double>(0.14159265358979323846264338327950288419716939937510), pi_minus_three, 2); | |
369 | CHECK_ULP_CLOSE(static_cast<double>(4. - 3.14159265358979323846264338327950288419716939937510), four_minus_pi, 2); | |
7c673cae | 370 | #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS |
20effc67 TL |
371 | CHECK_ULP_CLOSE(static_cast<double>(pow((3.14159265358979323846264338327950288419716939937510), 2.71828182845904523536028747135266249775724709369995)), pi_pow_e, 2); |
372 | CHECK_ULP_CLOSE(static_cast<double>(pow((3.14159265358979323846264338327950288419716939937510), 0.33333333333333333333333333333333333333333333333333)), cbrt_pi, 2); | |
373 | CHECK_ULP_CLOSE(static_cast<double>(exp(-0.5)), exp_minus_half, 2); | |
374 | CHECK_ULP_CLOSE(static_cast<double>(pow(2.71828182845904523536028747135266249775724709369995, 3.14159265358979323846264338327950288419716939937510)), e_pow_pi, 2); | |
7c673cae FG |
375 | |
376 | ||
377 | #else // Only double, so no suffix . | |
20effc67 TL |
378 | CHECK_ULP_CLOSE(static_cast<double>(pow((3.14159265358979323846264338327950288419716939937510), 2.71828182845904523536028747135266249775724709369995)), pi_pow_e, 2); |
379 | CHECK_ULP_CLOSE(static_cast<double>(pow((3.14159265358979323846264338327950288419716939937510), 0.33333333333333333333333333333333333333333333333333)), cbrt_pi, 2); | |
380 | CHECK_ULP_CLOSE(static_cast<double>(exp(-0.5)), exp_minus_half, 2); | |
7c673cae FG |
381 | #endif |
382 | // Rational fractions. | |
20effc67 TL |
383 | CHECK_ULP_CLOSE(static_cast<double>(0.333333333333333333333333333333333333333), third, 2); |
384 | CHECK_ULP_CLOSE(static_cast<double>(0.666666666666666666666666666666666666667), two_thirds, 2); | |
385 | CHECK_ULP_CLOSE(static_cast<double>(0.75), three_quarters, 2); | |
7c673cae | 386 | // Two and related. |
20effc67 TL |
387 | CHECK_ULP_CLOSE(static_cast<double>(sqrt(2.)), root_two, 2); |
388 | CHECK_ULP_CLOSE(static_cast<double>(sqrt(3.)), root_three, 2); | |
389 | CHECK_ULP_CLOSE(static_cast<double>(sqrt(2.)/2), half_root_two, 2); | |
390 | CHECK_ULP_CLOSE(static_cast<double>(log(2.)), ln_two, 2); | |
391 | CHECK_ULP_CLOSE(static_cast<double>(log(log(2.0))), ln_ln_two, 2); | |
392 | CHECK_ULP_CLOSE(static_cast<double>(sqrt(log(4.0))), root_ln_four, 2); | |
393 | CHECK_ULP_CLOSE(static_cast<double>(1/sqrt(2.0)), one_div_root_two, 2); | |
7c673cae FG |
394 | |
395 | // pi. | |
20effc67 TL |
396 | CHECK_ULP_CLOSE(static_cast<double>(3.14159265358979323846264338327950288419716939937510), pi, 2); |
397 | CHECK_ULP_CLOSE(static_cast<double>(3.14159265358979323846264338327950288419716939937510/2), half_pi, 2); | |
398 | CHECK_ULP_CLOSE(static_cast<double>(3.14159265358979323846264338327950288419716939937510/4), quarter_pi, 2); | |
399 | CHECK_ULP_CLOSE(static_cast<double>(3.14159265358979323846264338327950288419716939937510/3), third_pi, 2); | |
400 | CHECK_ULP_CLOSE(static_cast<double>(3.14159265358979323846264338327950288419716939937510/6), sixth_pi, 2); | |
401 | CHECK_ULP_CLOSE(static_cast<double>(2 * 3.14159265358979323846264338327950288419716939937510), two_pi, 2); | |
402 | CHECK_ULP_CLOSE(static_cast<double>(3 * 3.14159265358979323846264338327950288419716939937510 / 4), three_quarters_pi, 2); | |
403 | CHECK_ULP_CLOSE(static_cast<double>(4 * 3.14159265358979323846264338327950288419716939937510 / 3), four_thirds_pi, 2); | |
404 | CHECK_ULP_CLOSE(static_cast<double>(1 / (3.14159265358979323846264338327950288419716939937510)), one_div_pi, 2); | |
405 | CHECK_ULP_CLOSE(static_cast<double>(2 / (3.14159265358979323846264338327950288419716939937510)), two_div_pi, 2); | |
406 | CHECK_ULP_CLOSE(static_cast<double>(1 / (2 * 3.14159265358979323846264338327950288419716939937510)), one_div_two_pi, 2); | |
407 | CHECK_ULP_CLOSE(static_cast<double>(sqrt(3.14159265358979323846264338327950288419716939937510)), root_pi, 2); | |
408 | CHECK_ULP_CLOSE(static_cast<double>(sqrt(3.14159265358979323846264338327950288419716939937510 / 2)), root_half_pi, 2); | |
409 | CHECK_ULP_CLOSE(static_cast<double>(sqrt(2 * 3.14159265358979323846264338327950288419716939937510)), root_two_pi, 2); | |
410 | CHECK_ULP_CLOSE(static_cast<double>(1 / sqrt(3.14159265358979323846264338327950288419716939937510)), one_div_root_pi, 2); | |
411 | CHECK_ULP_CLOSE(static_cast<double>(2 / sqrt(3.14159265358979323846264338327950288419716939937510)), two_div_root_pi, 2); | |
412 | CHECK_ULP_CLOSE(static_cast<double>(1 / sqrt(2 * 3.14159265358979323846264338327950288419716939937510)), one_div_root_two_pi, 2); | |
413 | CHECK_ULP_CLOSE(static_cast<double>(sqrt(1. / 3.14159265358979323846264338327950288419716939937510)), root_one_div_pi, 2); | |
414 | CHECK_ULP_CLOSE(static_cast<double>(3.14159265358979323846264338327950288419716939937510 - 3.), pi_minus_three, 4 * 2 ); // 4 * 2 because of cancellation loss. | |
415 | CHECK_ULP_CLOSE(static_cast<double>(4. - 3.14159265358979323846264338327950288419716939937510), four_minus_pi, 4 ); | |
7c673cae | 416 | // |
20effc67 TL |
417 | CHECK_ULP_CLOSE(static_cast<double>(pow((3.14159265358979323846264338327950288419716939937510), 2.71828182845904523536028747135266249775724709369995)), pi_pow_e, 2); // See above. |
418 | CHECK_ULP_CLOSE(static_cast<double>(3.14159265358979323846264338327950288419716939937510 * 3.14159265358979323846264338327950288419716939937510), pi_sqr, 2); // See above. | |
419 | CHECK_ULP_CLOSE(static_cast<double>(3.14159265358979323846264338327950288419716939937510 * 3.14159265358979323846264338327950288419716939937510/6), pi_sqr_div_six, 2); // See above. | |
420 | CHECK_ULP_CLOSE(static_cast<double>(3.14159265358979323846264338327950288419716939937510 * 3.14159265358979323846264338327950288419716939937510 * 3.14159265358979323846264338327950288419716939937510), pi_cubed, 2); // See above. | |
7c673cae | 421 | |
20effc67 TL |
422 | // CHECK_ULP_CLOSE(static_cast<double>(3.14159265358979323846264338327950288419716939937510 * 3.14159265358979323846264338327950288419716939937510), cbrt_pi, 2); // See above. |
423 | CHECK_ULP_CLOSE(cbrt_pi * cbrt_pi * cbrt_pi, pi, 2); | |
424 | CHECK_ULP_CLOSE((static_cast<double>(1)/cbrt_pi), one_div_cbrt_pi, 2); | |
7c673cae FG |
425 | |
426 | // Euler | |
20effc67 | 427 | CHECK_ULP_CLOSE(static_cast<double>(2.71828182845904523536028747135266249775724709369995), e, 2); |
7c673cae | 428 | |
20effc67 TL |
429 | //CHECK_ULP_CLOSE(static_cast<double>(exp(-0.5)), exp_minus_half, 2); // See above. |
430 | CHECK_ULP_CLOSE(pow(e, pi), e_pow_pi, 2); // See also above. | |
431 | CHECK_ULP_CLOSE(sqrt(e), root_e, 2); | |
432 | CHECK_ULP_CLOSE(log10(e), log10_e, 2); | |
433 | CHECK_ULP_CLOSE(static_cast<double>(1)/log10(e), one_div_log10_e, 2); | |
7c673cae | 434 | |
f67539c2 | 435 | // Trigonometric |
20effc67 TL |
436 | CHECK_ULP_CLOSE(pi/180, degree, 2); |
437 | CHECK_ULP_CLOSE(180 / pi, radian, 2); | |
438 | CHECK_ULP_CLOSE(sin(1.), sin_one, 2); | |
439 | CHECK_ULP_CLOSE(cos(1.), cos_one, 2); | |
440 | CHECK_ULP_CLOSE(sinh(1.), sinh_one, 2); | |
441 | CHECK_ULP_CLOSE(cosh(1.), cosh_one, 2); | |
7c673cae FG |
442 | |
443 | // Phi | |
20effc67 TL |
444 | CHECK_ULP_CLOSE((1. + sqrt(5.)) /2, phi, 2); |
445 | CHECK_ULP_CLOSE(log((1. + sqrt(5.)) /2), ln_phi, 2); | |
446 | CHECK_ULP_CLOSE(1. / log((1. + sqrt(5.)) /2), one_div_ln_phi, 2); | |
7c673cae FG |
447 | |
448 | //Euler's Gamma | |
20effc67 TL |
449 | CHECK_ULP_CLOSE(0.57721566490153286060651209008240243104215933593992, euler, 2); // (sequence A001620 in OEIS). |
450 | CHECK_ULP_CLOSE(1./ 0.57721566490153286060651209008240243104215933593992, one_div_euler, 2); // (from sequence A001620 in OEIS). | |
451 | CHECK_ULP_CLOSE(0.57721566490153286060651209008240243104215933593992 * 0.57721566490153286060651209008240243104215933593992, euler_sqr, 2); // (from sequence A001620 in OEIS). | |
7c673cae FG |
452 | |
453 | // Misc | |
20effc67 TL |
454 | CHECK_ULP_CLOSE(1.644934066848226436472415166646025189218949901206, zeta_two, 2); // A013661 as a constant (usually base 10) in OEIS. |
455 | CHECK_ULP_CLOSE(1.20205690315959428539973816151144999076498629234049888179227, zeta_three, 2); // (sequence A002117 in OEIS) | |
456 | CHECK_ULP_CLOSE(.91596559417721901505460351493238411077414937428167213, catalan, 2); // A006752 as a constant in OEIS. | |
457 | CHECK_ULP_CLOSE(1.1395470994046486574927930193898461120875997958365518247216557100852480077060706857071875468869385150, extreme_value_skewness, 2); // Mathematica: N[12 Sqrt[6] Zeta[3]/Pi^3, 1101] | |
458 | CHECK_ULP_CLOSE(0.6311106578189371381918993515442277798440422031347194976580945856929268196174737254599050270325373067, rayleigh_skewness, 2); // Mathematica: N[2 Sqrt[Pi] (Pi - 3)/((4 - Pi)^(3/2)), 1100] | |
459 | CHECK_ULP_CLOSE(2.450893006876380628486604106197544154e-01, rayleigh_kurtosis_excess, 2); | |
460 | CHECK_ULP_CLOSE(2.68545200106530644530971483548179569382038229399446295305115234555721885953715200280114117493184769799515, khinchin, 4 ); // A002210 as a constant https://oeis.org/A002210/constant | |
461 | CHECK_ULP_CLOSE(1.2824271291006226368753425688697917277676889273250011, glaisher, 4 ); // https://oeis.org/A074962/constant | |
7c673cae FG |
462 | |
463 | } // template <class RealType>void test_spots(RealType) | |
464 | ||
465 | void test_long_double_spots() | |
466 | { | |
467 | // Basic sanity checks for constants in boost::math::long double_constants:: | |
468 | // for example: boost::math::long_double_constants::pi | |
469 | // (rather than boost::math::constants::pi<long double>() ). | |
470 | ||
20effc67 TL |
471 | // All constants are tested here using at least long double precision |
472 | // with independent calculated or listed values, | |
473 | // or calculations using long double (sometime a little less accurate). | |
7c673cae FG |
474 | using namespace boost::math::long_double_constants; |
475 | BOOST_MATH_STD_USING | |
476 | ||
20effc67 TL |
477 | CHECK_ULP_CLOSE(static_cast<long double>(3.14159265358979323846264338327950288419716939937510L), pi, 2); |
478 | CHECK_ULP_CLOSE(static_cast<long double>(sqrt(3.14159265358979323846264338327950288419716939937510L)), root_pi, 2); | |
479 | CHECK_ULP_CLOSE(static_cast<long double>(sqrt(3.14159265358979323846264338327950288419716939937510L/2)), root_half_pi, 2); | |
480 | CHECK_ULP_CLOSE(static_cast<long double>(sqrt(3.14159265358979323846264338327950288419716939937510L * 2)), root_two_pi, 2); | |
481 | CHECK_ULP_CLOSE(static_cast<long double>(sqrt(log(4.0L))), root_ln_four, 2); | |
482 | CHECK_ULP_CLOSE(static_cast<long double>(2.71828182845904523536028747135266249775724709369995L), e, 2); | |
483 | CHECK_ULP_CLOSE(static_cast<long double>(0.5), half, 2); | |
484 | CHECK_ULP_CLOSE(static_cast<long double>(0.57721566490153286060651209008240243104259335L), euler, 2); | |
485 | CHECK_ULP_CLOSE(static_cast<long double>(sqrt(2.0L)), root_two, 2); | |
486 | CHECK_ULP_CLOSE(static_cast<long double>(log(2.0L)), ln_two, 2); | |
487 | CHECK_ULP_CLOSE(static_cast<long double>(log(log(2.0L))), ln_ln_two, 2); | |
488 | CHECK_ULP_CLOSE(static_cast<long double>(1)/3, third, 2); | |
489 | CHECK_ULP_CLOSE(static_cast<long double>(2)/3, twothirds, 2); | |
490 | CHECK_ULP_CLOSE(static_cast<long double>(0.14159265358979323846264338327950288419716939937510L), pi_minus_three, 2); | |
491 | CHECK_ULP_CLOSE(static_cast<long double>(4.L - 3.14159265358979323846264338327950288419716939937510L), four_minus_pi, 2); | |
7c673cae | 492 | #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS |
20effc67 TL |
493 | CHECK_ULP_CLOSE(static_cast<long double>(pow((3.14159265358979323846264338327950288419716939937510L), 2.71828182845904523536028747135266249775724709369995L)), pi_pow_e, 2); |
494 | CHECK_ULP_CLOSE(static_cast<long double>(pow((3.14159265358979323846264338327950288419716939937510L), 0.33333333333333333333333333333333333333333333333333L)), cbrt_pi, 2); | |
495 | CHECK_ULP_CLOSE(static_cast<long double>(exp(-0.5L)), exp_minus_half, 2); | |
496 | CHECK_ULP_CLOSE(static_cast<long double>(pow(2.71828182845904523536028747135266249775724709369995L, 3.14159265358979323846264338327950288419716939937510L)), e_pow_pi, 2); | |
7c673cae FG |
497 | |
498 | ||
499 | #else // Only double, so no suffix L. | |
20effc67 TL |
500 | CHECK_ULP_CLOSE(static_cast<long double>(pow((3.14159265358979323846264338327950288419716939937510), 2.71828182845904523536028747135266249775724709369995)), pi_pow_e, 2); |
501 | CHECK_ULP_CLOSE(static_cast<long double>(pow((3.14159265358979323846264338327950288419716939937510), 0.33333333333333333333333333333333333333333333333333)), cbrt_pi, 2); | |
502 | CHECK_ULP_CLOSE(static_cast<long double>(exp(-0.5)), exp_minus_half, 2); | |
7c673cae FG |
503 | #endif |
504 | // Rational fractions. | |
20effc67 TL |
505 | CHECK_ULP_CLOSE(static_cast<long double>(0.333333333333333333333333333333333333333L), third, 2); |
506 | CHECK_ULP_CLOSE(static_cast<long double>(0.666666666666666666666666666666666666667L), two_thirds, 2); | |
507 | CHECK_ULP_CLOSE(static_cast<long double>(0.75L), three_quarters, 2); | |
7c673cae | 508 | // Two and related. |
20effc67 TL |
509 | CHECK_ULP_CLOSE(static_cast<long double>(sqrt(2.L)), root_two, 2); |
510 | CHECK_ULP_CLOSE(static_cast<long double>(sqrt(3.L)), root_three, 2); | |
511 | CHECK_ULP_CLOSE(static_cast<long double>(sqrt(2.L)/2), half_root_two, 2); | |
512 | CHECK_ULP_CLOSE(static_cast<long double>(log(2.L)), ln_two, 2); | |
513 | CHECK_ULP_CLOSE(static_cast<long double>(log(log(2.0L))), ln_ln_two, 2); | |
514 | CHECK_ULP_CLOSE(static_cast<long double>(sqrt(log(4.0L))), root_ln_four, 2); | |
515 | CHECK_ULP_CLOSE(static_cast<long double>(1/sqrt(2.0L)), one_div_root_two, 2); | |
7c673cae FG |
516 | |
517 | // pi. | |
20effc67 TL |
518 | CHECK_ULP_CLOSE(static_cast<long double>(3.14159265358979323846264338327950288419716939937510L), pi, 2); |
519 | CHECK_ULP_CLOSE(static_cast<long double>(3.14159265358979323846264338327950288419716939937510L/2), half_pi, 2); | |
520 | CHECK_ULP_CLOSE(static_cast<long double>(3.14159265358979323846264338327950288419716939937510L/4), quarter_pi, 2); | |
521 | CHECK_ULP_CLOSE(static_cast<long double>(3.14159265358979323846264338327950288419716939937510L/3), third_pi, 2); | |
522 | CHECK_ULP_CLOSE(static_cast<long double>(3.14159265358979323846264338327950288419716939937510L/6), sixth_pi, 2); | |
523 | CHECK_ULP_CLOSE(static_cast<long double>(2 * 3.14159265358979323846264338327950288419716939937510L), two_pi, 2); | |
524 | CHECK_ULP_CLOSE(static_cast<long double>(3 * 3.14159265358979323846264338327950288419716939937510L / 4), three_quarters_pi, 2); | |
525 | CHECK_ULP_CLOSE(static_cast<long double>(4 * 3.14159265358979323846264338327950288419716939937510L / 3), four_thirds_pi, 2); | |
526 | CHECK_ULP_CLOSE(static_cast<long double>(1 / (3.14159265358979323846264338327950288419716939937510L)), one_div_pi, 2); | |
527 | CHECK_ULP_CLOSE(static_cast<long double>(2 / (3.14159265358979323846264338327950288419716939937510L)), two_div_pi, 2); | |
528 | CHECK_ULP_CLOSE(static_cast<long double>(1 / (2 * 3.14159265358979323846264338327950288419716939937510L)), one_div_two_pi, 2); | |
529 | CHECK_ULP_CLOSE(static_cast<long double>(sqrt(3.14159265358979323846264338327950288419716939937510L)), root_pi, 2); | |
530 | CHECK_ULP_CLOSE(static_cast<long double>(sqrt(3.14159265358979323846264338327950288419716939937510L / 2)), root_half_pi, 2); | |
531 | CHECK_ULP_CLOSE(static_cast<long double>(sqrt(2 * 3.14159265358979323846264338327950288419716939937510L)), root_two_pi, 2); | |
532 | CHECK_ULP_CLOSE(static_cast<long double>(1 / sqrt(3.14159265358979323846264338327950288419716939937510L)), one_div_root_pi, 2); | |
533 | CHECK_ULP_CLOSE(static_cast<long double>(2 / sqrt(3.14159265358979323846264338327950288419716939937510L)), two_div_root_pi, 2); | |
534 | CHECK_ULP_CLOSE(static_cast<long double>(1 / sqrt(2 * 3.14159265358979323846264338327950288419716939937510L)), one_div_root_two_pi, 2); | |
535 | CHECK_ULP_CLOSE(static_cast<long double>(sqrt(1. / 3.14159265358979323846264338327950288419716939937510L)), root_one_div_pi, 2); | |
536 | CHECK_ULP_CLOSE(static_cast<long double>(3.14159265358979323846264338327950288419716939937510L - 3.L), pi_minus_three, 4 * 4 ); // 4 * 2 because of cancellation loss. | |
537 | CHECK_ULP_CLOSE(static_cast<long double>(4.L - 3.14159265358979323846264338327950288419716939937510L), four_minus_pi, 4 ); | |
7c673cae | 538 | // |
20effc67 TL |
539 | CHECK_ULP_CLOSE(static_cast<long double>(pow((3.14159265358979323846264338327950288419716939937510L), 2.71828182845904523536028747135266249775724709369995L)), pi_pow_e, 2); // See above. |
540 | CHECK_ULP_CLOSE(static_cast<long double>(3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L), pi_sqr, 2); // See above. | |
541 | CHECK_ULP_CLOSE(static_cast<long double>(3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L/6), pi_sqr_div_six, 2); // See above. | |
542 | CHECK_ULP_CLOSE(static_cast<long double>(3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L), pi_cubed, 2); // See above. | |
7c673cae | 543 | |
20effc67 TL |
544 | // CHECK_ULP_CLOSE(static_cast<long double>(3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L), cbrt_pi, 2); // See above. |
545 | CHECK_ULP_CLOSE(cbrt_pi * cbrt_pi * cbrt_pi, pi, 2); | |
546 | CHECK_ULP_CLOSE((static_cast<long double>(1)/cbrt_pi), one_div_cbrt_pi, 2); | |
7c673cae | 547 | |
20effc67 TL |
548 | CHECK_ULP_CLOSE(static_cast<long double>(6.366197723675813430755350534900574481378385829618257E-1L), two_div_pi, 4 * 3); // 2/pi |
549 | CHECK_ULP_CLOSE(static_cast<long double>(7.97884560802865355879892119868763736951717262329869E-1L), root_two_div_pi, 4 * 3); // sqrt(2/pi) | |
7c673cae FG |
550 | |
551 | // Euler | |
20effc67 | 552 | CHECK_ULP_CLOSE(static_cast<long double>(2.71828182845904523536028747135266249775724709369995L), e, 2); |
7c673cae | 553 | |
20effc67 TL |
554 | //CHECK_ULP_CLOSE(static_cast<long double>(exp(-0.5L)), exp_minus_half, 2); // See above. |
555 | CHECK_ULP_CLOSE(pow(e, pi), e_pow_pi, 2); // See also above. | |
556 | CHECK_ULP_CLOSE(sqrt(e), root_e, 2); | |
557 | CHECK_ULP_CLOSE(log10(e), log10_e, 2); | |
558 | CHECK_ULP_CLOSE(static_cast<long double>(1)/log10(e), one_div_log10_e, 2); | |
7c673cae | 559 | |
f67539c2 | 560 | // Trigonometric |
20effc67 TL |
561 | CHECK_ULP_CLOSE(pi/180, degree, 2); |
562 | CHECK_ULP_CLOSE(180 / pi, radian, 2); | |
563 | CHECK_ULP_CLOSE(sin(1.L), sin_one, 2); | |
564 | CHECK_ULP_CLOSE(cos(1.L), cos_one, 2); | |
565 | CHECK_ULP_CLOSE(sinh(1.L), sinh_one, 2); | |
566 | CHECK_ULP_CLOSE(cosh(1.L), cosh_one, 2); | |
7c673cae FG |
567 | |
568 | // Phi | |
20effc67 TL |
569 | CHECK_ULP_CLOSE((1.L + sqrt(5.L)) /2, phi, 2); |
570 | CHECK_ULP_CLOSE(log((1.L + sqrt(5.L)) /2), ln_phi, 2); | |
571 | CHECK_ULP_CLOSE(1.L / log((1.L + sqrt(5.L)) /2), one_div_ln_phi, 2); | |
7c673cae FG |
572 | |
573 | //Euler's Gamma | |
20effc67 TL |
574 | CHECK_ULP_CLOSE(0.57721566490153286060651209008240243104215933593992L, euler, 2); // (sequence A001620 in OEIS). |
575 | CHECK_ULP_CLOSE(1.L/ 0.57721566490153286060651209008240243104215933593992L, one_div_euler, 2); // (from sequence A001620 in OEIS). | |
576 | CHECK_ULP_CLOSE(0.57721566490153286060651209008240243104215933593992L * 0.57721566490153286060651209008240243104215933593992L, euler_sqr, 2); // (from sequence A001620 in OEIS). | |
7c673cae FG |
577 | |
578 | // Misc | |
20effc67 TL |
579 | CHECK_ULP_CLOSE(1.644934066848226436472415166646025189218949901206L, zeta_two, 2); // A013661 as a constant (usually base 10) in OEIS. |
580 | CHECK_ULP_CLOSE(1.20205690315959428539973816151144999076498629234049888179227L, zeta_three, 2); // (sequence A002117 in OEIS) | |
581 | CHECK_ULP_CLOSE(.91596559417721901505460351493238411077414937428167213L, catalan, 2); // A006752 as a constant in OEIS. | |
582 | CHECK_ULP_CLOSE(1.1395470994046486574927930193898461120875997958365518247216557100852480077060706857071875468869385150L, extreme_value_skewness, 2); // Mathematica: N[12 Sqrt[6] Zeta[3]/Pi^3, 1101] | |
583 | CHECK_ULP_CLOSE(0.6311106578189371381918993515442277798440422031347194976580945856929268196174737254599050270325373067L, rayleigh_skewness, 2); // Mathematica: N[2 Sqrt[Pi] (Pi - 3)/((4 - Pi)^(3/2)), 1100] | |
584 | CHECK_ULP_CLOSE(2.450893006876380628486604106197544154e-01L, rayleigh_kurtosis_excess, 2); | |
585 | CHECK_ULP_CLOSE(2.68545200106530644530971483548179569382038229399446295305115234555721885953715200280114117493184769799515L, khinchin, 4 ); // A002210 as a constant https://oeis.org/A002210/constant | |
586 | CHECK_ULP_CLOSE(1.2824271291006226368753425688697917277676889273250011L, glaisher, 4 ); // https://oeis.org/A074962/constant | |
7c673cae FG |
587 | |
588 | } // template <class RealType>void test_spots(RealType) | |
589 | ||
590 | template <class Policy> | |
591 | void test_real_concept_policy(const Policy&) | |
592 | { | |
593 | // Basic sanity checks for constants using real_concept. | |
594 | // Parameter Policy is used to control precision. | |
595 | ||
596 | using boost::math::concepts::real_concept; | |
7c673cae FG |
597 | //typedef typename boost::math::policies::precision<boost::math::concepts::real_concept, boost::math::policies::policy<> >::type t1; |
598 | // A precision of zero means we don't know what the precision of this type is until runtime. | |
599 | //std::cout << "Precision for type " << typeid(boost::math::concepts::real_concept).name() << " is " << t1::value << "." << std::endl; | |
600 | ||
601 | using namespace boost::math::constants; | |
602 | BOOST_MATH_STD_USING | |
603 | ||
20effc67 TL |
604 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L, (pi<real_concept, Policy>)(), 2); |
605 | CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L), (root_pi<real_concept, Policy>)(), 2); | |
606 | CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L/2), (root_half_pi<real_concept, Policy>)(), 2); | |
607 | CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L * 2), (root_two_pi<real_concept, Policy>)(), 2); | |
608 | CHECK_ULP_CLOSE(sqrt(log(4.0L)), (root_ln_four<real_concept, Policy>)(), 2); | |
609 | CHECK_ULP_CLOSE(2.71828182845904523536028747135266249775724709369995L, (e<real_concept, Policy>)(), 2); | |
610 | CHECK_ULP_CLOSE(0.5, (half<real_concept, Policy>)(), 2); | |
611 | CHECK_ULP_CLOSE(0.57721566490153286060651209008240243104259335L, (euler<real_concept, Policy>)(), 2); | |
612 | CHECK_ULP_CLOSE(sqrt(2.0L), (root_two<real_concept, Policy>)(), 2); | |
613 | CHECK_ULP_CLOSE(log(2.0L), (ln_two<real_concept, Policy>)(), 2); | |
614 | CHECK_ULP_CLOSE(log(log(2.0L)), (ln_ln_two<real_concept, Policy>)(), 2); | |
615 | CHECK_ULP_CLOSE(static_cast<long double>(1)/3, (third<real_concept, Policy>)(), 2); | |
616 | CHECK_ULP_CLOSE(static_cast<long double>(2)/3, (twothirds<real_concept, Policy>)(), 2); | |
617 | CHECK_ULP_CLOSE(0.14159265358979323846264338327950288419716939937510L, (pi_minus_three<real_concept, Policy>)(), 2); | |
618 | CHECK_ULP_CLOSE(4.L - 3.14159265358979323846264338327950288419716939937510L, (four_minus_pi<real_concept, Policy>)(), 2); | |
7c673cae | 619 | #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS |
20effc67 TL |
620 | CHECK_ULP_CLOSE(pow((3.14159265358979323846264338327950288419716939937510L), 2.71828182845904523536028747135266249775724709369995L), (pi_pow_e<real_concept, Policy>)(), 2); |
621 | CHECK_ULP_CLOSE(pow((3.14159265358979323846264338327950288419716939937510L), 0.33333333333333333333333333333333333333333333333333L), (cbrt_pi<real_concept, Policy>)(), 2); | |
622 | CHECK_ULP_CLOSE(exp(-0.5L), (exp_minus_half<real_concept, Policy>)(), 2); | |
623 | CHECK_ULP_CLOSE(pow(2.71828182845904523536028747135266249775724709369995L, 3.14159265358979323846264338327950288419716939937510L), (e_pow_pi<real_concept, Policy>)(), 2); | |
7c673cae FG |
624 | |
625 | ||
626 | #else // Only double, so no suffix L. | |
20effc67 TL |
627 | CHECK_ULP_CLOSE(pow((3.14159265358979323846264338327950288419716939937510), 2.71828182845904523536028747135266249775724709369995), (pi_pow_e<real_concept, Policy>)(), 2); |
628 | CHECK_ULP_CLOSE(pow((3.14159265358979323846264338327950288419716939937510), 0.33333333333333333333333333333333333333333333333333), (cbrt_pi<real_concept, Policy>)(), 2); | |
629 | CHECK_ULP_CLOSE(exp(-0.5), (exp_minus_half<real_concept, Policy>)(), 2); | |
7c673cae FG |
630 | #endif |
631 | // Rational fractions. | |
20effc67 TL |
632 | CHECK_ULP_CLOSE(0.333333333333333333333333333333333333333L, (third<real_concept, Policy>)(), 2); |
633 | CHECK_ULP_CLOSE(0.666666666666666666666666666666666666667L, (two_thirds<real_concept, Policy>)(), 2); | |
634 | CHECK_ULP_CLOSE(0.75L, (three_quarters<real_concept, Policy>)(), 2); | |
7c673cae | 635 | // Two and related. |
20effc67 TL |
636 | CHECK_ULP_CLOSE(sqrt(2.L), (root_two<real_concept, Policy>)(), 2); |
637 | CHECK_ULP_CLOSE(sqrt(3.L), (root_three<real_concept, Policy>)(), 2); | |
638 | CHECK_ULP_CLOSE(sqrt(2.L)/2, (half_root_two<real_concept, Policy>)(), 2); | |
639 | CHECK_ULP_CLOSE(log(2.L), (ln_two<real_concept, Policy>)(), 2); | |
640 | CHECK_ULP_CLOSE(log(log(2.0L)), (ln_ln_two<real_concept, Policy>)(), 2); | |
641 | CHECK_ULP_CLOSE(sqrt(log(4.0L)), (root_ln_four<real_concept, Policy>)(), 2); | |
642 | CHECK_ULP_CLOSE(1/sqrt(2.0L), (one_div_root_two<real_concept, Policy>)(), 2); | |
7c673cae FG |
643 | |
644 | // pi. | |
20effc67 TL |
645 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L, (pi<real_concept, Policy>)(), 2); |
646 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L/2, (half_pi<real_concept, Policy>)(), 2); | |
647 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L/4, (quarter_pi<real_concept, Policy>)(), 2); | |
648 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L/3, (third_pi<real_concept, Policy>)(), 2); | |
649 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L/6, (sixth_pi<real_concept, Policy>)(), 2); | |
650 | CHECK_ULP_CLOSE(2 * 3.14159265358979323846264338327950288419716939937510L, (two_pi<real_concept, Policy>)(), 2); | |
651 | CHECK_ULP_CLOSE(3 * 3.14159265358979323846264338327950288419716939937510L / 4, (three_quarters_pi<real_concept, Policy>)(), 2); | |
652 | CHECK_ULP_CLOSE(4 * 3.14159265358979323846264338327950288419716939937510L / 3, (four_thirds_pi<real_concept, Policy>)(), 2); | |
653 | CHECK_ULP_CLOSE(1 / (3.14159265358979323846264338327950288419716939937510L), (one_div_pi<real_concept, Policy>)(), 2); | |
654 | CHECK_ULP_CLOSE(2 / (3.14159265358979323846264338327950288419716939937510L), (two_div_pi<real_concept, Policy>)(), 2); | |
655 | CHECK_ULP_CLOSE(1 / (2 * 3.14159265358979323846264338327950288419716939937510L), (one_div_two_pi<real_concept, Policy>)(), 2); | |
656 | CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L), (root_pi<real_concept, Policy>)(), 2); | |
657 | CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L / 2), (root_half_pi<real_concept, Policy>)(), 2); | |
658 | CHECK_ULP_CLOSE(sqrt(2 * 3.14159265358979323846264338327950288419716939937510L), (root_two_pi<real_concept, Policy>)(), 2); | |
659 | CHECK_ULP_CLOSE(1 / sqrt(3.14159265358979323846264338327950288419716939937510L), (one_div_root_pi<real_concept, Policy>)(), 2); | |
660 | CHECK_ULP_CLOSE(2 / sqrt(3.14159265358979323846264338327950288419716939937510L), (two_div_root_pi<real_concept, Policy>)(), 2); | |
661 | CHECK_ULP_CLOSE(1 / sqrt(2 * 3.14159265358979323846264338327950288419716939937510L), (one_div_root_two_pi<real_concept, Policy>)(), 2); | |
662 | CHECK_ULP_CLOSE(sqrt(1. / 3.14159265358979323846264338327950288419716939937510L), (root_one_div_pi<real_concept, Policy>)(), 2); | |
663 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L - 3.L, (pi_minus_three<real_concept, Policy>)(), 4 * 4 ); // 4 * 2 because of cancellation loss. | |
664 | CHECK_ULP_CLOSE(4.L - 3.14159265358979323846264338327950288419716939937510L, (four_minus_pi<real_concept, Policy>)(), 4 ); | |
7c673cae | 665 | // |
20effc67 TL |
666 | CHECK_ULP_CLOSE(pow((3.14159265358979323846264338327950288419716939937510L), 2.71828182845904523536028747135266249775724709369995L), (pi_pow_e<real_concept, Policy>)(), 2); // See above. |
667 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L, (pi_sqr<real_concept, Policy>)(), 2); // See above. | |
668 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L/6, (pi_sqr_div_six<real_concept, Policy>)(), 2); // See above. | |
669 | CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L, (pi_cubed<real_concept, Policy>)(), 2); // See above. | |
7c673cae | 670 | |
20effc67 TL |
671 | // CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L * 3.14159265358979323846264338327950288419716939937510L, (cbrt_pi<real_concept, Policy>)(), 2); // See above. |
672 | CHECK_ULP_CLOSE((cbrt_pi<real_concept, Policy>)() * (cbrt_pi<real_concept, Policy>)() * (cbrt_pi<real_concept, Policy>)(), (pi<real_concept, Policy>)(), 2); | |
673 | CHECK_ULP_CLOSE((1)/(cbrt_pi<real_concept, Policy>)(), (one_div_cbrt_pi<real_concept, Policy>)(), 2); | |
7c673cae FG |
674 | |
675 | // Euler | |
20effc67 | 676 | CHECK_ULP_CLOSE(2.71828182845904523536028747135266249775724709369995L, (e<real_concept, Policy>)(), 2); |
7c673cae | 677 | |
20effc67 TL |
678 | //CHECK_ULP_CLOSE(exp(-0.5L), (exp_minus_half<real_concept, Policy>)(), 2); // See above. |
679 | CHECK_ULP_CLOSE(pow(e<real_concept, Policy>(), (pi<real_concept, Policy>)()), (e_pow_pi<real_concept, Policy>)(), 2); // See also above. | |
680 | CHECK_ULP_CLOSE(sqrt(e<real_concept, Policy>()), (root_e<real_concept, Policy>)(), 2); | |
681 | CHECK_ULP_CLOSE(log10(e<real_concept, Policy>()), (log10_e<real_concept, Policy>)(), 2); | |
682 | CHECK_ULP_CLOSE(1/log10(e<real_concept, Policy>()), (one_div_log10_e<real_concept, Policy>)(), 2); | |
683 | CHECK_ULP_CLOSE((1/ln_two<real_concept, Policy>()), (log2_e<real_concept, Policy>)(), 2); | |
7c673cae | 684 | |
f67539c2 | 685 | // Trigonometric |
20effc67 TL |
686 | CHECK_ULP_CLOSE((pi<real_concept, Policy>)()/180, (degree<real_concept, Policy>)(), 2); |
687 | CHECK_ULP_CLOSE(180 / (pi<real_concept, Policy>)(), (radian<real_concept, Policy>)(), 2); | |
688 | CHECK_ULP_CLOSE(sin(1.L), (sin_one<real_concept, Policy>)(), 2); | |
689 | CHECK_ULP_CLOSE(cos(1.L), (cos_one<real_concept, Policy>)(), 2); | |
690 | CHECK_ULP_CLOSE(sinh(1.L), (sinh_one<real_concept, Policy>)(), 2); | |
691 | CHECK_ULP_CLOSE(cosh(1.L), (cosh_one<real_concept, Policy>)(), 2); | |
7c673cae FG |
692 | |
693 | // Phi | |
20effc67 TL |
694 | CHECK_ULP_CLOSE((1.L + sqrt(5.L)) /2, (phi<real_concept, Policy>)(), 2); |
695 | CHECK_ULP_CLOSE(log((1.L + sqrt(5.L)) /2), (ln_phi<real_concept, Policy>)(), 2); | |
696 | CHECK_ULP_CLOSE(1.L / log((1.L + sqrt(5.L)) /2), (one_div_ln_phi<real_concept, Policy>)(), 2); | |
7c673cae FG |
697 | |
698 | //Euler's Gamma | |
20effc67 TL |
699 | CHECK_ULP_CLOSE(0.57721566490153286060651209008240243104215933593992L, (euler<real_concept, Policy>)(), 2); // (sequence A001620 in OEIS). |
700 | CHECK_ULP_CLOSE(1.L/ 0.57721566490153286060651209008240243104215933593992L, (one_div_euler<real_concept, Policy>)(), 2); // (from sequence A001620 in OEIS). | |
701 | CHECK_ULP_CLOSE(0.57721566490153286060651209008240243104215933593992L * 0.57721566490153286060651209008240243104215933593992L, (euler_sqr<real_concept, Policy>)(), 2); // (from sequence A001620 in OEIS). | |
7c673cae FG |
702 | |
703 | // Misc | |
20effc67 TL |
704 | CHECK_ULP_CLOSE(1.644934066848226436472415166646025189218949901206L, (zeta_two<real_concept, Policy>)(), 2); // A013661 as a constant (usually base 10) in OEIS. |
705 | CHECK_ULP_CLOSE(1.20205690315959428539973816151144999076498629234049888179227L, (zeta_three<real_concept, Policy>)(), 2); // (sequence A002117 in OEIS) | |
706 | CHECK_ULP_CLOSE(.91596559417721901505460351493238411077414937428167213L, (catalan<real_concept, Policy>)(), 2); // A006752 as a constant in OEIS. | |
707 | CHECK_ULP_CLOSE(1.1395470994046486574927930193898461120875997958365518247216557100852480077060706857071875468869385150L, (extreme_value_skewness<real_concept, Policy>)(), 2); // Mathematica: N[12 Sqrt[6] Zeta[3]/Pi^3, 1101] | |
708 | CHECK_ULP_CLOSE(0.6311106578189371381918993515442277798440422031347194976580945856929268196174737254599050270325373067L, (rayleigh_skewness<real_concept, Policy>)(), 2); // Mathematica: N[2 Sqrt[Pi] (Pi - 3)/((4 - Pi)^(3/2)), 1100] | |
709 | CHECK_ULP_CLOSE(2.450893006876380628486604106197544154e-01L, (rayleigh_kurtosis_excess<real_concept, Policy>)(), 2); | |
710 | CHECK_ULP_CLOSE(2.68545200106530644530971483548179569382038229399446295305115234555721885953715200280114117493184769799515L, (khinchin<real_concept, Policy>)(), 4 ); // A002210 as a constant https://oeis.org/A002210/constant | |
711 | CHECK_ULP_CLOSE(1.2824271291006226368753425688697917277676889273250011L, (glaisher<real_concept, Policy>)(), 4 ); // https://oeis.org/A074962/constant | |
7c673cae FG |
712 | |
713 | // | |
714 | // Last of all come the test cases that behave differently if we're calculating the constants on the fly: | |
715 | // | |
716 | if(boost::math::tools::digits<real_concept>() > boost::math::constants::max_string_digits) | |
717 | { | |
20effc67 TL |
718 | // This suffers from cancellation error, so increased 4: |
719 | CHECK_ULP_CLOSE((static_cast<real_concept>(4. - 3.14159265358979323846264338327950288419716939937510L)), (four_minus_pi<real_concept, Policy>)(), 4 * 3); | |
720 | CHECK_ULP_CLOSE((static_cast<real_concept>(0.14159265358979323846264338327950288419716939937510L)), (pi_minus_three<real_concept, Policy>)(), 4 * 3); | |
7c673cae FG |
721 | } |
722 | else | |
723 | { | |
20effc67 TL |
724 | CHECK_ULP_CLOSE((static_cast<real_concept>(4. - 3.14159265358979323846264338327950288419716939937510L)), (four_minus_pi<real_concept, Policy>)(), 2); |
725 | CHECK_ULP_CLOSE((static_cast<real_concept>(0.14159265358979323846264338327950288419716939937510L)), (pi_minus_three<real_concept, Policy>)(), 2); | |
7c673cae FG |
726 | } |
727 | ||
728 | } // template <class boost::math::concepts::real_concept>void test_spots(boost::math::concepts::real_concept) | |
729 | ||
20effc67 | 730 | #ifdef BOOST_MATH_HAS_FLOAT128 |
7c673cae FG |
731 | void test_float128() |
732 | { | |
7c673cae FG |
733 | __float128 p = boost::math::constants::pi<__float128>(); |
734 | __float128 r = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651Q; | |
20effc67 | 735 | CHECK_ULP_CLOSE(boost::multiprecision::float128(p), boost::multiprecision::float128(r), 2); |
7c673cae FG |
736 | } |
737 | #endif | |
738 | ||
739 | void test_constexpr() | |
740 | { | |
741 | #ifndef BOOST_NO_CXX11_CONSTEXPR | |
742 | constexpr float f1 = boost::math::constants::pi<float>(); | |
743 | constexpr double f2 = boost::math::constants::pi<double>(); | |
744 | constexpr long double f3 = boost::math::constants::pi<long double>(); | |
92f5a8d4 TL |
745 | constexpr float fval2 = boost::math::float_constants::pi; |
746 | constexpr double dval2 = boost::math::double_constants::pi; | |
747 | constexpr long double ldval2 = boost::math::long_double_constants::pi; | |
7c673cae FG |
748 | (void)f1; |
749 | (void)f2; | |
750 | (void)f3; | |
92f5a8d4 TL |
751 | (void) fval2; |
752 | (void) dval2; | |
753 | (void) ldval2; | |
7c673cae FG |
754 | #ifdef BOOST_MATH_USE_FLOAT128 |
755 | constexpr __float128 f4 = boost::math::constants::pi<__float128>(); | |
756 | (void)f4; | |
757 | #endif | |
758 | #endif | |
759 | } | |
760 | ||
20effc67 TL |
761 | #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900) |
762 | void test_feigenbaum() | |
7c673cae | 763 | { |
20effc67 TL |
764 | // This constant takes weeks to calculate. |
765 | // So if the requested precision > precomputed precision, we need an error message. | |
766 | using boost::multiprecision::cpp_bin_float; | |
767 | using boost::multiprecision::number; | |
768 | auto f64 = boost::math::constants::first_feigenbaum<double>(); | |
769 | using Real100 = number<cpp_bin_float<300>>; | |
770 | auto f = boost::math::constants::first_feigenbaum<Real100>(); | |
771 | CHECK_ULP_CLOSE(static_cast<double>(f), f64, 0); | |
772 | Real100 g{"4.6692016091029906718532038204662016172581855774757686327456513430041343302113147371386897440239480138171659848551898151344086271420279325223124429888908908599449354632367134115324817142199474556443658237932020095610583305754586176522220703854106467494942849814533917262005687556659523398756038256372256480040951071283890611844702775854285419801113440175002428585382498335715522052236087250291678860362674527213399057131606875345083433934446103706309452019115876972432273589838903794946257251289097948986768334611626889116563123474460575179539122045562472807095202198199094558581946136877445617396074115614074243754435499204869180982648652368438702799649017397793425134723808737136211601860128186102056381818354097598477964173900328936171432159878240789776614391395764037760537119096932066998361984288981837003229412030210655743295550388845849737034727532121925706958414074661841981961006129640161487712944415901405467941800198133253378592493365883070459999938375411726563553016862529032210862320550634510679399023341675"}; | |
773 | CHECK_ULP_CLOSE(f, g, 0); | |
774 | } | |
775 | ||
776 | template<typename Real> | |
777 | void test_plastic() | |
778 | { | |
779 | Real P = boost::math::constants::plastic<Real>(); | |
780 | Real residual = P*P*P - P -1; | |
781 | using std::abs; | |
782 | CHECK_LE(abs(residual), 4*std::numeric_limits<Real>::epsilon()); | |
783 | } | |
784 | ||
785 | template<typename Real> | |
786 | void test_gauss() | |
787 | { | |
788 | using boost::math::tools::agm; | |
789 | using std::sqrt; | |
790 | Real G_computed = boost::math::constants::gauss<Real>(); | |
791 | Real G_expected = Real(1)/agm(sqrt(Real(2)), Real(1)); | |
792 | CHECK_ULP_CLOSE(G_expected, G_computed, 1); | |
793 | CHECK_LE(G_computed, Real(0.8347)); | |
794 | CHECK_LE(Real(0.8346), G_computed); | |
795 | } | |
796 | ||
797 | template<typename Real> | |
798 | void test_dottie() | |
799 | { | |
800 | using boost::math::constants::dottie; | |
801 | using std::cos; | |
802 | CHECK_ULP_CLOSE(dottie<Real>(), cos(dottie<Real>()), 1); | |
803 | } | |
804 | ||
805 | template<typename Real> | |
806 | void test_reciprocal_fibonacci() | |
807 | { | |
808 | using boost::math::constants::reciprocal_fibonacci; | |
809 | CHECK_LE(reciprocal_fibonacci<Real>(), Real(3.36)); | |
810 | CHECK_LE(Real(3.35), reciprocal_fibonacci<Real>()); | |
811 | } | |
812 | ||
813 | template<typename Real> | |
814 | void test_laplace_limit() | |
815 | { | |
816 | using std::exp; | |
817 | using std::sqrt; | |
818 | using boost::math::constants::laplace_limit; | |
819 | Real ll = laplace_limit<Real>(); | |
820 | Real tmp = sqrt(1+ll*ll); | |
821 | CHECK_ULP_CLOSE(ll*exp(tmp), 1 + tmp, 1); | |
822 | } | |
823 | ||
824 | #endif | |
7c673cae | 825 | |
20effc67 TL |
826 | int main() |
827 | { | |
828 | // Basic sanity-check spot values. | |
7c673cae FG |
829 | test_float_spots(); // Test float_constants, like boost::math::float_constants::pi; |
830 | test_double_spots(); // Test double_constants. | |
7c673cae | 831 | test_long_double_spots(); // Test long_double_constants. |
20effc67 | 832 | #ifdef BOOST_MATH_HAS_FLOAT128 |
7c673cae FG |
833 | test_float128(); |
834 | #endif | |
835 | test_constexpr(); | |
836 | ||
7c673cae FG |
837 | // (Parameter value, arbitrarily zero, only communicates the floating-point type). |
838 | test_spots(0.0F); // Test float. | |
839 | test_spots(0.0); // Test double. | |
7c673cae | 840 | test_spots(0.0L); // Test long double. |
7c673cae | 841 | |
20effc67 TL |
842 | #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900) |
843 | test_feigenbaum(); | |
844 | test_plastic<float>(); | |
845 | test_plastic<double>(); | |
846 | test_plastic<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<400>>>(); | |
847 | test_gauss<float>(); | |
848 | test_gauss<double>(); | |
849 | test_gauss<long double>(); | |
850 | test_gauss<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<400>>>(); | |
851 | test_dottie<float>(); | |
852 | test_dottie<double>(); | |
853 | test_dottie<long double>(); | |
854 | test_dottie<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<400>>>(); | |
855 | test_laplace_limit<float>(); | |
856 | test_laplace_limit<double>(); | |
857 | test_laplace_limit<long double>(); | |
858 | test_laplace_limit<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<400>>>(); | |
859 | #endif | |
860 | return boost::math::test::report_errors(); | |
861 | } |