]>
Commit | Line | Data |
---|---|---|
b4688136 ESR |
1 | // { dg-do run { target c++11 } } |
2 | // { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__" } | |
7c62b943 | 3 | // |
7adcbafe | 4 | // Copyright (C) 2016-2022 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 | // comp_ellint_2 | |
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_Boost|): 1.1102230246251565e-15 at index 13 |
43 | // max(|f - f_Boost| / |f_Boost|): 7.3722846590663481e-16 | |
44 | // mean(f - f_Boost): 1.7529837230923525e-16 | |
45 | // variance(f - f_Boost): 1.8020397140465364e-33 | |
46 | // stddev(f - f_Boost): 4.2450438325729176e-17 | |
47 | const testcase_comp_ellint_2<double> | |
48 | data001[19] = | |
49 | { | |
50 | { 1.1716970527816142, -0.90000000000000002, 0.0 }, | |
51 | { 1.2763499431699064, -0.80000000000000004, 0.0 }, | |
52 | { 1.3556611355719554, -0.69999999999999996, 0.0 }, | |
53 | { 1.4180833944487243, -0.59999999999999998, 0.0 }, | |
54 | { 1.4674622093394272, -0.50000000000000000, 0.0 }, | |
55 | { 1.5059416123600404, -0.39999999999999991, 0.0 }, | |
56 | { 1.5348334649232491, -0.29999999999999993, 0.0 }, | |
57 | { 1.5549685462425293, -0.19999999999999996, 0.0 }, | |
58 | { 1.5668619420216683, -0.099999999999999978, 0.0 }, | |
59 | { 1.5707963267948966, 0.0000000000000000, 0.0 }, | |
60 | { 1.5668619420216683, 0.10000000000000009, 0.0 }, | |
61 | { 1.5549685462425293, 0.20000000000000018, 0.0 }, | |
62 | { 1.5348334649232491, 0.30000000000000004, 0.0 }, | |
63 | { 1.5059416123600402, 0.40000000000000013, 0.0 }, | |
64 | { 1.4674622093394272, 0.50000000000000000, 0.0 }, | |
65 | { 1.4180833944487241, 0.60000000000000009, 0.0 }, | |
66 | { 1.3556611355719554, 0.70000000000000018, 0.0 }, | |
67 | { 1.2763499431699064, 0.80000000000000004, 0.0 }, | |
68 | { 1.1716970527816140, 0.90000000000000013, 0.0 }, | |
7c62b943 | 69 | }; |
b4688136 | 70 | const double toler001 = 2.5000000000000020e-13; |
7c62b943 | 71 | |
b4688136 ESR |
72 | template<typename Ret, unsigned int Num> |
73 | void | |
74 | test(const testcase_comp_ellint_2<Ret> (&data)[Num], Ret toler) | |
75 | { | |
76 | bool test __attribute__((unused)) = true; | |
77 | const Ret eps = std::numeric_limits<Ret>::epsilon(); | |
78 | Ret max_abs_diff = -Ret(1); | |
79 | Ret max_abs_frac = -Ret(1); | |
80 | unsigned int num_datum = Num; | |
81 | for (unsigned int i = 0; i < num_datum; ++i) | |
82 | { | |
83 | const Ret f = std::tr1::comp_ellint_2(data[i].k); | |
84 | const Ret f0 = data[i].f0; | |
85 | const Ret diff = f - f0; | |
86 | if (std::abs(diff) > max_abs_diff) | |
87 | max_abs_diff = std::abs(diff); | |
88 | if (std::abs(f0) > Ret(10) * eps | |
89 | && std::abs(f) > Ret(10) * eps) | |
90 | { | |
91 | const Ret frac = diff / f0; | |
92 | if (std::abs(frac) > max_abs_frac) | |
93 | max_abs_frac = std::abs(frac); | |
94 | } | |
95 | } | |
96 | VERIFY(max_abs_frac < toler); | |
97 | } | |
7c62b943 | 98 | |
b4688136 ESR |
99 | int |
100 | main() | |
7c62b943 | 101 | { |
b4688136 | 102 | test(data001, toler001); |
7c62b943 BK |
103 | return 0; |
104 | } |