2017-11-18 Edward Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libstdc++-v3 / testsuite / ext / special_functions / airy_ai / check_value.cc
blob10f2f7c3f17101dc3f9df3166c17203d167256df
1 // { dg-do run { target c++11 } }
2 // { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__" }
3 //
4 // Copyright (C) 2016-2017 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 // airy_ai
23 // Compare against values generated by the GNU Scientific Library.
24 // The GSL can be found on the web: http://www.gnu.org/software/gsl/
25 #include <limits>
26 #include <cmath>
27 #if defined(__TEST_DEBUG)
28 # include <iostream>
29 # define VERIFY(A) \
30 if (!(A)) \
31 { \
32 std::cout << "line " << __LINE__ \
33 << " max_abs_frac = " << max_abs_frac \
34 << std::endl; \
36 #else
37 # include <testsuite_hooks.h>
38 #endif
39 #include <specfun_testcase.h>
41 // Test data.
42 // max(|f - f_GSL|): 2.0261570199409107e-15 at index 0
43 // max(|f - f_GSL| / |f_GSL|): 5.7527019513802774e-14
44 // mean(f - f_GSL): 5.7893945880945940e-17
45 // variance(f - f_GSL): 8.5887539970087062e-35
46 // stddev(f - f_GSL): 9.2675530734971811e-18
47 const testcase_airy_ai<double>
48 data001[41] =
50 { 0.040241238486444071, -10.000000000000000, 0.0 },
51 { 0.31910324771912801, -9.5000000000000000, 0.0 },
52 { -0.022133721547341240, -9.0000000000000000, 0.0 },
53 { -0.33029023763020882, -8.5000000000000000, 0.0 },
54 { -0.052705050356385910, -8.0000000000000000, 0.0 },
55 { 0.32177571638064789, -7.5000000000000000, 0.0 },
56 { 0.18428083525050609, -7.0000000000000000, 0.0 },
57 { -0.23802030199711663, -6.5000000000000000, 0.0 },
58 { -0.32914517362982321, -6.0000000000000000, 0.0 },
59 { 0.017781541276574383, -5.5000000000000000, 0.0 },
60 { 0.35076100902411411, -5.0000000000000000, 0.0 },
61 { 0.29215278105595921, -4.5000000000000000, 0.0 },
62 { -0.070265532949289680, -4.0000000000000000, 0.0 },
63 { -0.37553382314043182, -3.5000000000000000, 0.0 },
64 { -0.37881429367765823, -3.0000000000000000, 0.0 },
65 { -0.11232506769296607, -2.5000000000000000, 0.0 },
66 { 0.22740742820168561, -2.0000000000000000, 0.0 },
67 { 0.46425657774886947, -1.5000000000000000, 0.0 },
68 { 0.53556088329235207, -1.0000000000000000, 0.0 },
69 { 0.47572809161053958, -0.50000000000000000, 0.0 },
70 { 0.35502805388781722, 0.0000000000000000, 0.0 },
71 { 0.23169360648083348, 0.50000000000000000, 0.0 },
72 { 0.13529241631288141, 1.0000000000000000, 0.0 },
73 { 0.071749497008105428, 1.5000000000000000, 0.0 },
74 { 0.034924130423274372, 2.0000000000000000, 0.0 },
75 { 0.015725923380470481, 2.5000000000000000, 0.0 },
76 { 0.0065911393574607175, 3.0000000000000000, 0.0 },
77 { 0.0025840987869896349, 3.5000000000000000, 0.0 },
78 { 0.00095156385120480195, 4.0000000000000000, 0.0 },
79 { 0.00033025032351430934, 4.5000000000000000, 0.0 },
80 { 0.00010834442813607434, 5.0000000000000000, 0.0 },
81 { 3.3685311908599812e-05, 5.5000000000000000, 0.0 },
82 { 9.9476943602528973e-06, 6.0000000000000000, 0.0 },
83 { 2.7958823432049148e-06, 6.5000000000000000, 0.0 },
84 { 7.4921288639971570e-07, 7.0000000000000000, 0.0 },
85 { 1.9172560675134295e-07, 7.5000000000000000, 0.0 },
86 { 4.6922076160992236e-08, 8.0000000000000000, 0.0 },
87 { 1.0997009755195515e-08, 8.5000000000000000, 0.0 },
88 { 2.4711684308724904e-09, 9.0000000000000000, 0.0 },
89 { 5.3302637046174900e-10, 9.5000000000000000, 0.0 },
90 { 1.1047532552898652e-10, 10.000000000000000, 0.0 },
92 const double toler001 = 5.0000000000000029e-12;
94 template<typename Ret, unsigned int Num>
95 void
96 test(const testcase_airy_ai<Ret> (&data)[Num], Ret toler)
98 bool test __attribute__((unused)) = true;
99 const Ret eps = std::numeric_limits<Ret>::epsilon();
100 Ret max_abs_diff = -Ret(1);
101 Ret max_abs_frac = -Ret(1);
102 unsigned int num_datum = Num;
103 for (unsigned int i = 0; i < num_datum; ++i)
105 const Ret f = __gnu_cxx::airy_ai(data[i].x);
106 const Ret f0 = data[i].f0;
107 const Ret diff = f - f0;
108 if (std::abs(diff) > max_abs_diff)
109 max_abs_diff = std::abs(diff);
110 if (std::abs(f0) > Ret(10) * eps
111 && std::abs(f) > Ret(10) * eps)
113 const Ret frac = diff / f0;
114 if (std::abs(frac) > max_abs_frac)
115 max_abs_frac = std::abs(frac);
118 VERIFY(max_abs_frac < toler);
122 main()
124 test(data001, toler001);
125 return 0;