]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/math/test/test_erf.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / math / test / test_erf.cpp
CommitLineData
7c673cae
FG
1// Copyright John Maddock 2006.
2// Copyright Paul A. Bristow 2007
3// Use, modification and distribution are subject to the
4// Boost Software License, Version 1.0. (See accompanying file
5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7#include <pch_light.hpp>
8#include "test_erf.hpp"
9
10//
11// DESCRIPTION:
12// ~~~~~~~~~~~~
13//
14// This file tests the functions erf, erfc, and the inverses
15// erf_inv and erfc_inv. There are two sets of tests, spot
16// tests which compare our results with selected values computed
17// using the online special function calculator at
18// functions.wolfram.com, while the bulk of the accuracy tests
19// use values generated with NTL::RR at 1000-bit precision
20// and our generic versions of these functions.
21//
22// Note that when this file is first run on a new platform many of
23// these tests will fail: the default accuracy is 1 epsilon which
24// is too tight for most platforms. In this situation you will
25// need to cast a human eye over the error rates reported and make
26// a judgement as to whether they are acceptable. Either way please
27// report the results to the Boost mailing list. Acceptable rates of
28// error are marked up below as a series of regular expressions that
29// identify the compiler/stdlib/platform/data-type/test-data/test-function
30// along with the maximum expected peek and RMS mean errors for that
31// test.
32//
33
34void expected_results()
35{
36 //
37 // Define the max and mean errors expected for
38 // various compilers and platforms.
39 //
40 const char* largest_type;
41#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
42 if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
43 {
44 largest_type = "(long\\s+)?double|real_concept";
45 }
46 else
47 {
48 largest_type = "long double|real_concept";
49 }
50#else
51 largest_type = "(long\\s+)?double";
52#endif
53 //
54 // On MacOS X erfc has much higher error levels than
55 // expected: given that the implementation is basically
56 // just a rational function evaluation combined with
57 // exponentiation, we conclude that exp and pow are less
58 // accurate on this platform, especially when the result
59 // is outside the range of a double.
60 //
61 add_expected_result(
62 ".*", // compiler
63 ".*", // stdlib
64 "Mac OS", // platform
65 largest_type, // test type(s)
66 "Erf Function:.*Large.*", // test data group
67 "erfc", 4300, 1300); // test function
68 add_expected_result(
69 ".*", // compiler
70 ".*", // stdlib
71 "Mac OS", // platform
72 largest_type, // test type(s)
73 "Erf Function:.*", // test data group
74 "erfc", 40, 10); // test function
75
76 add_expected_result(
77 ".*", // compiler
78 ".*", // stdlib
79 ".*", // platform
80 "real_concept", // test type(s)
81 "Erf Function:.*", // test data group
82 "erfc?", 20, 6); // test function
83 add_expected_result(
84 ".*", // compiler
85 ".*", // stdlib
86 ".*", // platform
87 "real_concept", // test type(s)
88 "Inverse Erfc.*", // test data group
89 "erfc_inv", 80, 10); // test function
90
91
92 //
93 // Catch all cases come last:
94 //
95 add_expected_result(
96 ".*", // compiler
97 ".*", // stdlib
98 ".*", // platform
99 ".*", // test type(s)
100 "Erf Function:.*", // test data group
101 "erfc?", 2, 2); // test function
102 add_expected_result(
103 ".*aCC.*", // compiler
104 ".*", // stdlib
105 ".*", // platform
106 ".*", // test type(s)
107 "Inverse Erfc.*", // test data group
108 "erfc_inv", 80, 10); // test function
109 add_expected_result(
110 ".*", // compiler
111 ".*", // stdlib
112 ".*", // platform
113 ".*", // test type(s)
114 "Inverse Erf.*", // test data group
115 "erfc?_inv", 18, 4); // test function
116
117 //
118 // Finish off by printing out the compiler/stdlib/platform names,
119 // we do this to make it easier to mark up expected error rates.
120 //
121 std::cout << "Tests run with " << BOOST_COMPILER << ", "
122 << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
123}
124
125BOOST_AUTO_TEST_CASE( test_main )
126{
127 BOOST_MATH_CONTROL_FP;
128 test_spots(0.0F, "float");
129 test_spots(0.0, "double");
130#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
131 test_spots(0.0L, "long double");
1e59de90 132#if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x582)) && !defined(BOOST_MATH_NO_REAL_CONCEPT_TESTS)
7c673cae
FG
133 test_spots(boost::math::concepts::real_concept(0.1), "real_concept");
134#endif
135#endif
136
137 expected_results();
138
139 test_erf(0.1F, "float");
140 test_erf(0.1, "double");
141#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
142 test_erf(0.1L, "long double");
143#ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
20effc67 144#if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x582))
7c673cae
FG
145 test_erf(boost::math::concepts::real_concept(0.1), "real_concept");
146#endif
147#endif
148#else
149 std::cout << "<note>The long double tests have been disabled on this platform "
150 "either because the long double overloads of the usual math functions are "
151 "not available at all, or because they are too inaccurate for these tests "
152 "to pass.</note>" << std::endl;
153#endif
154}
155
156/*
157
158Output:
159
160test_erf.cpp
161Compiling manifest to resources...
162Linking...
163Embedding manifest...
164Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_erf.exe"
165Running 1 test case...
166Testing basic sanity checks for type float
167Testing basic sanity checks for type double
168Testing basic sanity checks for type long double
169Testing basic sanity checks for type real_concept
170Tests run with Microsoft Visual C++ version 8.0, Dinkumware standard library version 405, Win32
171Testing Erf Function: Small Values with type float
172~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
173boost::math::erf<float> Max = 0 RMS Mean=0
174boost::math::erfc<float> Max = 0 RMS Mean=0
175Testing Erf Function: Medium Values with type float
176~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177boost::math::erf<float> Max = 0 RMS Mean=0
178boost::math::erfc<float> Max = 0 RMS Mean=0
179Testing Erf Function: Large Values with type float
180~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
181boost::math::erf<float> Max = 0 RMS Mean=0
182boost::math::erfc<float> Max = 0 RMS Mean=0
183Testing Inverse Erf Function with type float
184~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
185boost::math::erf_inv<float> Max = 0 RMS Mean=0
186Testing Inverse Erfc Function with type float
187~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
188boost::math::erfc_inv<float> Max = 0 RMS Mean=0
189Testing Erf Function: Small Values with type double
190~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191boost::math::erf<double> Max = 0 RMS Mean=0
192boost::math::erfc<double> Max = 0.7857 RMS Mean=0.06415
193 worst case at row: 149
194 { 0.3343, 0.3636, 0.6364 }
195Testing Erf Function: Medium Values with type double
196~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
197boost::math::erf<double> Max = 0.9219 RMS Mean=0.1016
198 worst case at row: 273
199 { 0.5252, 0.5424, 0.4576 }
200boost::math::erfc<double> Max = 1.08 RMS Mean=0.3224
201 worst case at row: 287
202 { 0.8461, 0.7685, 0.2315 }
203Testing Erf Function: Large Values with type double
204~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
205boost::math::erf<double> Max = 0 RMS Mean=0
206boost::math::erfc<double> Max = 1.048 RMS Mean=0.2032
207 worst case at row: 50
208 { 20.96, 1, 4.182e-193 }
209Testing Inverse Erf Function with type double
210~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
211boost::math::erf_inv<double> Max = 1.124 RMS Mean=0.5082
212 worst case at row: 98
213 { 0.9881, 1.779 }
214Testing Inverse Erfc Function with type double
215~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
216boost::math::erfc_inv<double> Max = 1.124 RMS Mean=0.5006
217 worst case at row: 98
218 { 1.988, -1.779 }
219Testing Erf Function: Small Values with type long double
220~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
221boost::math::erf<long double> Max = 0 RMS Mean=0
222boost::math::erfc<long double> Max = 0.7857 RMS Mean=0.06415
223 worst case at row: 149
224 { 0.3343, 0.3636, 0.6364 }
225Testing Erf Function: Medium Values with type long double
226~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
227boost::math::erf<long double> Max = 0.9219 RMS Mean=0.1016
228 worst case at row: 273
229 { 0.5252, 0.5424, 0.4576 }
230boost::math::erfc<long double> Max = 1.08 RMS Mean=0.3224
231 worst case at row: 287
232 { 0.8461, 0.7685, 0.2315 }
233Testing Erf Function: Large Values with type long double
234~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235boost::math::erf<long double> Max = 0 RMS Mean=0
236boost::math::erfc<long double> Max = 1.048 RMS Mean=0.2032
237 worst case at row: 50
238 { 20.96, 1, 4.182e-193 }
239Testing Inverse Erf Function with type long double
240~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
241boost::math::erf_inv<long double> Max = 1.124 RMS Mean=0.5082
242 worst case at row: 98
243 { 0.9881, 1.779 }
244Testing Inverse Erfc Function with type long double
245~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
246boost::math::erfc_inv<long double> Max = 1.124 RMS Mean=0.5006
247 worst case at row: 98
248 { 1.988, -1.779 }
249Testing Erf Function: Small Values with type real_concept
250~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
251boost::math::erf<real_concept> Max = 1.271 RMS Mean=0.5381
252 worst case at row: 144
253 { 0.0109, 0.0123, 0.9877 }
254boost::math::erfc<real_concept> Max = 0.7857 RMS Mean=0.07777
255 worst case at row: 149
256 { 0.3343, 0.3636, 0.6364 }
257Testing Erf Function: Medium Values with type real_concept
258~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259boost::math::erf<real_concept> Max = 22.5 RMS Mean=4.224
260 worst case at row: 233
261 { -0.7852, -0.7332, 1.733 }
262Peak error greater than expected value of 20
263i:/boost-sandbox/math_toolkit/libs/math/test/handle_test_result.hpp(146): error in "test_main_caller( argc, argv )": check bounds.first >= max_error_found failed
264boost::math::erfc<real_concept> Max = 97.77 RMS Mean=8.373
265 worst case at row: 289
266 { 0.9849, 0.8363, 0.1637 }
267Peak error greater than expected value of 20
268i:/boost-sandbox/math_toolkit/libs/math/test/handle_test_result.hpp(146): error in "test_main_caller( argc, argv )": check bounds.first >= max_error_found failed
269Mean error greater than expected value of 6
270i:/boost-sandbox/math_toolkit/libs/math/test/handle_test_result.hpp(151): error in "test_main_caller( argc, argv )": check bounds.second >= mean_error_found failed
271Testing Erf Function: Large Values with type real_concept
272~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
273boost::math::erf<real_concept> Max = 0 RMS Mean=0
274boost::math::erfc<real_concept> Max = 1.395 RMS Mean=0.2908
275 worst case at row: 11
276 { 10.99, 1, 1.87e-054 }
277Testing Inverse Erf Function with type real_concept
278~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
279boost::math::erf_inv<real_concept> Max = 1.124 RMS Mean=0.5082
280 worst case at row: 98
281 { 0.9881, 1.779 }
282Testing Inverse Erfc Function with type real_concept
283~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
284boost::math::erfc_inv<real_concept> Max = 1.124 RMS Mean=0.5006
285 worst case at row: 98
286 { 1.988, -1.779 }
287Test suite "Test Program" failed with:
288 181 assertions out of 184 passed
289 3 assertions out of 184 failed
290 1 test case out of 1 failed
291 Test case "test_main_caller( argc, argv )" failed with:
292 181 assertions out of 184 passed
293 3 assertions out of 184 failed
294Build Time 0:15
295
296*/