]>
Commit | Line | Data |
---|---|---|
b4688136 ESR |
1 | // { dg-do run { target c++11 } } |
2 | // { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__" } | |
7c62b943 | 3 | // |
a5544970 | 4 | // Copyright (C) 2016-2019 Free Software Foundation, Inc. |
7c62b943 BK |
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 | |
748086b7 | 9 | // Free Software Foundation; either version 3, or (at your option) |
7c62b943 BK |
10 | // any later version. |
11 | // | |
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. | |
16 | // | |
17 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
18 | // with this library; see the file COPYING3. If not see |
19 | // <http://www.gnu.org/licenses/>. | |
7c62b943 BK |
20 | |
21 | // expint | |
22 | ||
7c62b943 BK |
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/ | |
b4688136 | 25 | #include <limits> |
7c62b943 BK |
26 | #include <tr1/cmath> |
27 | #if defined(__TEST_DEBUG) | |
b4688136 ESR |
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; \ | |
35 | } | |
7c62b943 | 36 | #else |
b4688136 | 37 | # include <testsuite_hooks.h> |
7c62b943 | 38 | #endif |
b4688136 | 39 | #include <specfun_testcase.h> |
7c62b943 BK |
40 | |
41 | // Test data. | |
b4688136 ESR |
42 | // max(|f - f_GSL|): 4.9960036108132044e-16 at index 49 |
43 | // max(|f - f_GSL| / |f_GSL|): 2.2772878171680836e-15 | |
44 | // mean(f - f_GSL): 1.1295166444684511e-17 | |
45 | // variance(f - f_GSL): 4.9654719514602855e-33 | |
46 | // stddev(f - f_GSL): 7.0466104982894328e-17 | |
47 | const testcase_expint<double> | |
48 | data001[50] = | |
49 | { | |
50 | { -3.7832640295504591e-24, -50.000000000000000, 0.0 }, | |
51 | { -1.0489811642368024e-23, -49.000000000000000, 0.0 }, | |
52 | { -2.9096641904058423e-23, -48.000000000000000, 0.0 }, | |
53 | { -8.0741978427258127e-23, -47.000000000000000, 0.0 }, | |
54 | { -2.2415317597442998e-22, -46.000000000000000, 0.0 }, | |
55 | { -6.2256908094623848e-22, -45.000000000000000, 0.0 }, | |
56 | { -1.7299598742816476e-21, -44.000000000000000, 0.0 }, | |
57 | { -4.8094965569500181e-21, -43.000000000000000, 0.0 }, | |
58 | { -1.3377908810011775e-20, -42.000000000000000, 0.0 }, | |
59 | { -3.7231667764599780e-20, -41.000000000000000, 0.0 }, | |
60 | { -1.0367732614516570e-19, -40.000000000000000, 0.0 }, | |
61 | { -2.8887793015227007e-19, -39.000000000000000, 0.0 }, | |
62 | { -8.0541069142907499e-19, -38.000000000000000, 0.0 }, | |
63 | { -2.2470206975885710e-18, -37.000000000000000, 0.0 }, | |
64 | { -6.2733390097622421e-18, -36.000000000000000, 0.0 }, | |
65 | { -1.7527059389947371e-17, -35.000000000000000, 0.0 }, | |
66 | { -4.9006761183927874e-17, -34.000000000000000, 0.0 }, | |
67 | { -1.3713843484487468e-16, -33.000000000000000, 0.0 }, | |
68 | { -3.8409618012250671e-16, -32.000000000000000, 0.0 }, | |
69 | { -1.0767670386162381e-15, -31.000000000000000, 0.0 }, | |
70 | { -3.0215520106888124e-15, -30.000000000000000, 0.0 }, | |
71 | { -8.4877597783535634e-15, -29.000000000000000, 0.0 }, | |
72 | { -2.3869415119337330e-14, -28.000000000000000, 0.0 }, | |
73 | { -6.7206374352620390e-14, -27.000000000000000, 0.0 }, | |
74 | { -1.8946858856749785e-13, -26.000000000000000, 0.0 }, | |
75 | { -5.3488997553402167e-13, -25.000000000000000, 0.0 }, | |
76 | { -1.5123058939997059e-12, -24.000000000000000, 0.0 }, | |
77 | { -4.2826847956656722e-12, -23.000000000000000, 0.0 }, | |
78 | { -1.2149378956204371e-11, -22.000000000000000, 0.0 }, | |
79 | { -3.4532012671467559e-11, -21.000000000000000, 0.0 }, | |
80 | { -9.8355252906498815e-11, -20.000000000000000, 0.0 }, | |
81 | { -2.8078290970607954e-10, -19.000000000000000, 0.0 }, | |
82 | { -8.0360903448286769e-10, -18.000000000000000, 0.0 }, | |
83 | { -2.3064319898216543e-09, -17.000000000000000, 0.0 }, | |
84 | { -6.6404872494410427e-09, -16.000000000000000, 0.0 }, | |
85 | { -1.9186278921478670e-08, -15.000000000000000, 0.0 }, | |
86 | { -5.5656311111451816e-08, -14.000000000000000, 0.0 }, | |
87 | { -1.6218662188014328e-07, -13.000000000000000, 0.0 }, | |
88 | { -4.7510818246724931e-07, -12.000000000000000, 0.0 }, | |
89 | { -1.4003003042474418e-06, -11.000000000000000, 0.0 }, | |
90 | { -4.1569689296853246e-06, -10.000000000000000, 0.0 }, | |
91 | { -1.2447354178006272e-05, -9.0000000000000000, 0.0 }, | |
92 | { -3.7665622843924906e-05, -8.0000000000000000, 0.0 }, | |
93 | { -0.00011548173161033820, -7.0000000000000000, 0.0 }, | |
94 | { -0.00036008245216265862, -6.0000000000000000, 0.0 }, | |
95 | { -0.0011482955912753257, -5.0000000000000000, 0.0 }, | |
96 | { -0.0037793524098489063, -4.0000000000000000, 0.0 }, | |
97 | { -0.013048381094197037, -3.0000000000000000, 0.0 }, | |
98 | { -0.048900510708061125, -2.0000000000000000, 0.0 }, | |
99 | { -0.21938393439552029, -1.0000000000000000, 0.0 }, | |
7c62b943 | 100 | }; |
b4688136 ESR |
101 | const double toler001 = 2.5000000000000020e-13; |
102 | // expint | |
7c62b943 | 103 | |
b4688136 ESR |
104 | |
105 | // Test data. | |
106 | // max(|f - f_GSL|): 16384.000000000000 at index 48 | |
107 | // max(|f - f_GSL| / |f_GSL|): 1.2494807514688476e-15 | |
108 | // mean(f - f_GSL): 371.15283351771996 | |
109 | // variance(f - f_GSL): inf | |
110 | // stddev(f - f_GSL): 7.1444587641577012e+253 | |
111 | const testcase_expint<double> | |
112 | data002[50] = | |
7c62b943 | 113 | { |
b4688136 ESR |
114 | { 1.8951178163559366, 1.0000000000000000, 0.0 }, |
115 | { 4.9542343560018907, 2.0000000000000000, 0.0 }, | |
116 | { 9.9338325706254160, 3.0000000000000000, 0.0 }, | |
117 | { 19.630874470056217, 4.0000000000000000, 0.0 }, | |
118 | { 40.185275355803178, 5.0000000000000000, 0.0 }, | |
119 | { 85.989762142439204, 6.0000000000000000, 0.0 }, | |
120 | { 191.50474333550136, 7.0000000000000000, 0.0 }, | |
121 | { 440.37989953483833, 8.0000000000000000, 0.0 }, | |
122 | { 1037.8782907170896, 9.0000000000000000, 0.0 }, | |
123 | { 2492.2289762418782, 10.000000000000000, 0.0 }, | |
124 | { 6071.4063740986112, 11.000000000000000, 0.0 }, | |
125 | { 14959.532666397528, 12.000000000000000, 0.0 }, | |
126 | { 37197.688490689041, 13.000000000000000, 0.0 }, | |
127 | { 93192.513633965369, 14.000000000000000, 0.0 }, | |
128 | { 234955.85249076830, 15.000000000000000, 0.0 }, | |
129 | { 595560.99867083691, 16.000000000000000, 0.0 }, | |
130 | { 1516637.8940425171, 17.000000000000000, 0.0 }, | |
131 | { 3877904.3305974435, 18.000000000000000, 0.0 }, | |
132 | { 9950907.2510468438, 19.000000000000000, 0.0 }, | |
133 | { 25615652.664056588, 20.000000000000000, 0.0 }, | |
134 | { 66127186.355484933, 21.000000000000000, 0.0 }, | |
135 | { 171144671.30036369, 22.000000000000000, 0.0 }, | |
136 | { 443966369.83027118, 23.000000000000000, 0.0 }, | |
137 | { 1154115391.8491828, 24.000000000000000, 0.0 }, | |
138 | { 3005950906.5255494, 25.000000000000000, 0.0 }, | |
139 | { 7842940991.8981876, 26.000000000000000, 0.0 }, | |
140 | { 20496497119.880810, 27.000000000000000, 0.0 }, | |
141 | { 53645118592.314682, 28.000000000000000, 0.0 }, | |
142 | { 140599195758.40689, 29.000000000000000, 0.0 }, | |
143 | { 368973209407.27417, 30.000000000000000, 0.0 }, | |
144 | { 969455575968.39392, 31.000000000000000, 0.0 }, | |
145 | { 2550043566357.7871, 32.000000000000000, 0.0 }, | |
146 | { 6714640184076.4971, 33.000000000000000, 0.0 }, | |
147 | { 17698037244116.266, 34.000000000000000, 0.0 }, | |
148 | { 46690550144661.602, 35.000000000000000, 0.0 }, | |
149 | { 123285207991209.75, 36.000000000000000, 0.0 }, | |
150 | { 325798899867226.50, 37.000000000000000, 0.0 }, | |
151 | { 861638819996578.75, 38.000000000000000, 0.0 }, | |
152 | { 2280446200301902.5, 39.000000000000000, 0.0 }, | |
153 | { 6039718263611242.0, 40.000000000000000, 0.0 }, | |
154 | { 16006649143245042., 41.000000000000000, 0.0 }, | |
155 | { 42447960921368512., 42.000000000000000, 0.0 }, | |
156 | { 1.1263482901669666e+17, 43.000000000000000, 0.0 }, | |
157 | { 2.9904447186323366e+17, 44.000000000000000, 0.0 }, | |
158 | { 7.9439160357044531e+17, 45.000000000000000, 0.0 }, | |
159 | { 2.1113423886478239e+18, 46.000000000000000, 0.0 }, | |
160 | { 5.6143296808103424e+18, 47.000000000000000, 0.0 }, | |
161 | { 1.4936302131129930e+19, 48.000000000000000, 0.0 }, | |
162 | { 3.9754427479037444e+19, 49.000000000000000, 0.0 }, | |
163 | { 1.0585636897131690e+20, 50.000000000000000, 0.0 }, | |
164 | }; | |
165 | const double toler002 = 2.5000000000000020e-13; | |
166 | ||
167 | template<typename Ret, unsigned int Num> | |
168 | void | |
169 | test(const testcase_expint<Ret> (&data)[Num], Ret toler) | |
170 | { | |
171 | bool test __attribute__((unused)) = true; | |
172 | const Ret eps = std::numeric_limits<Ret>::epsilon(); | |
173 | Ret max_abs_diff = -Ret(1); | |
174 | Ret max_abs_frac = -Ret(1); | |
175 | unsigned int num_datum = Num; | |
176 | for (unsigned int i = 0; i < num_datum; ++i) | |
177 | { | |
178 | const Ret f = std::tr1::expint(data[i].x); | |
179 | const Ret f0 = data[i].f0; | |
180 | const Ret diff = f - f0; | |
181 | if (std::abs(diff) > max_abs_diff) | |
182 | max_abs_diff = std::abs(diff); | |
183 | if (std::abs(f0) > Ret(10) * eps | |
184 | && std::abs(f) > Ret(10) * eps) | |
185 | { | |
186 | const Ret frac = diff / f0; | |
187 | if (std::abs(frac) > max_abs_frac) | |
188 | max_abs_frac = std::abs(frac); | |
189 | } | |
190 | } | |
191 | VERIFY(max_abs_frac < toler); | |
192 | } | |
7c62b943 | 193 | |
b4688136 ESR |
194 | int |
195 | main() | |
7c62b943 | 196 | { |
b4688136 ESR |
197 | test(data001, toler001); |
198 | test(data002, toler002); | |
7c62b943 BK |
199 | return 0; |
200 | } |