]>
Commit | Line | Data |
---|---|---|
7c62b943 BK |
1 | // 2007-02-04 Edward Smith-Rowland <3dw4rd@verizon.net> |
2 | // | |
a945c346 | 3 | // Copyright (C) 2007-2024 Free Software Foundation, Inc. |
7c62b943 BK |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
7c62b943 BK |
9 | // any later version. |
10 | // | |
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | // | |
16 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
7c62b943 BK |
19 | |
20 | // expint | |
21 | ||
22 | ||
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 | ||
26 | #include <tr1/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; \ | |
35 | } | |
36 | #else | |
37 | #include <testsuite_hooks.h> | |
38 | #endif | |
39 | #include "../testcase.h" | |
40 | ||
41 | ||
42 | // Test data. | |
43 | testcase_expint<double> data001[] = { | |
44 | { 1.8951178163559366, 1.0000000000000000 }, | |
45 | { 4.9542343560018907, 2.0000000000000000 }, | |
46 | { 9.9338325706254160, 3.0000000000000000 }, | |
47 | { 19.630874470056217, 4.0000000000000000 }, | |
48 | { 40.185275355803178, 5.0000000000000000 }, | |
49 | { 85.989762142439204, 6.0000000000000000 }, | |
50 | { 191.50474333550139, 7.0000000000000000 }, | |
51 | { 440.37989953483827, 8.0000000000000000 }, | |
52 | { 1037.8782907170896, 9.0000000000000000 }, | |
53 | { 2492.2289762418782, 10.000000000000000 }, | |
54 | { 6071.4063740986112, 11.000000000000000 }, | |
55 | { 14959.532666397527, 12.000000000000000 }, | |
56 | { 37197.688490689041, 13.000000000000000 }, | |
57 | { 93192.513633965369, 14.000000000000000 }, | |
58 | { 234955.85249076830, 15.000000000000000 }, | |
59 | { 595560.99867083703, 16.000000000000000 }, | |
60 | { 1516637.8940425171, 17.000000000000000 }, | |
61 | { 3877904.3305974435, 18.000000000000000 }, | |
62 | { 9950907.2510468438, 19.000000000000000 }, | |
63 | { 25615652.664056588, 20.000000000000000 }, | |
64 | { 66127186.355484918, 21.000000000000000 }, | |
65 | { 171144671.30036369, 22.000000000000000 }, | |
66 | { 443966369.83027118, 23.000000000000000 }, | |
67 | { 1154115391.8491828, 24.000000000000000 }, | |
68 | { 3005950906.5255489, 25.000000000000000 }, | |
69 | { 7842940991.8981876, 26.000000000000000 }, | |
70 | { 20496497119.880810, 27.000000000000000 }, | |
71 | { 53645118592.314682, 28.000000000000000 }, | |
72 | { 140599195758.40689, 29.000000000000000 }, | |
73 | { 368973209407.27423, 30.000000000000000 }, | |
74 | { 969455575968.39392, 31.000000000000000 }, | |
75 | { 2550043566357.7866, 32.000000000000000 }, | |
76 | { 6714640184076.4980, 33.000000000000000 }, | |
77 | { 17698037244116.266, 34.000000000000000 }, | |
78 | { 46690550144661.594, 35.000000000000000 }, | |
79 | { 123285207991209.75, 36.000000000000000 }, | |
80 | { 325798899867226.44, 37.000000000000000 }, | |
81 | { 861638819996578.62, 38.000000000000000 }, | |
82 | { 2280446200301902.5, 39.000000000000000 }, | |
83 | { 6039718263611242.0, 40.000000000000000 }, | |
84 | { 16006649143245042., 41.000000000000000 }, | |
85 | { 42447960921368504., 42.000000000000000 }, | |
86 | { 1.1263482901669667e+17, 43.000000000000000 }, | |
87 | { 2.9904447186323366e+17, 44.000000000000000 }, | |
88 | { 7.9439160357044531e+17, 45.000000000000000 }, | |
89 | { 2.1113423886478239e+18, 46.000000000000000 }, | |
90 | { 5.6143296808103434e+18, 47.000000000000000 }, | |
91 | { 1.4936302131129930e+19, 48.000000000000000 }, | |
92 | { 3.9754427479037444e+19, 49.000000000000000 }, | |
93 | { 1.0585636897131690e+20, 50.000000000000000 }, | |
94 | }; | |
95 | ||
96 | // Test function. | |
97 | template <typename Tp> | |
98 | void test001() | |
99 | { | |
100 | const Tp eps = std::numeric_limits<Tp>::epsilon(); | |
101 | Tp max_abs_diff = -Tp(1); | |
102 | Tp max_abs_frac = -Tp(1); | |
103 | unsigned int num_datum = sizeof(data001) | |
104 | / sizeof(testcase_expint<double>); | |
105 | for (unsigned int i = 0; i < num_datum; ++i) | |
106 | { | |
107 | const Tp f = std::tr1::expint(Tp(data001[i].x)); | |
108 | const Tp f0 = data001[i].f0; | |
109 | const Tp diff = f - f0; | |
110 | if (std::abs(diff) > max_abs_diff) | |
111 | max_abs_diff = std::abs(diff); | |
112 | if (std::abs(f0) > Tp(10) * eps | |
113 | && std::abs(f) > Tp(10) * eps) | |
114 | { | |
115 | const Tp frac = diff / f0; | |
116 | if (std::abs(frac) > max_abs_frac) | |
117 | max_abs_frac = std::abs(frac); | |
118 | } | |
119 | } | |
120 | VERIFY(max_abs_frac < Tp(2.5000000000000020e-13)); | |
121 | } | |
122 | ||
123 | int main(int, char**) | |
124 | { | |
125 | test001<double>(); | |
126 | return 0; | |
127 | } |