]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/special_functions/04_comp_ellint_1/check_value.cc
Implement TR29124 C++ special Math Functions.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / special_functions / 04_comp_ellint_1 / check_value.cc
1 // { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__" }
2 //
3 // Copyright (C) 2016 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 3, or (at your option)
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
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // comp_ellint_1
21
22 // Compare against values generated by the GNU Scientific Library.
23 // The GSL can be found on the web: http://www.gnu.org/software/gsl/
24 #include <limits>
25 #include <cmath>
26 #if defined(__TEST_DEBUG)
27 # include <iostream>
28 # define VERIFY(A) \
29 if (!(A)) \
30 { \
31 std::cout << "line " << __LINE__ \
32 << " max_abs_frac = " << max_abs_frac \
33 << std::endl; \
34 }
35 #else
36 # include <testsuite_hooks.h>
37 #endif
38 #include <specfun_testcase.h>
39
40 // Test data.
41 // max(|f - f_GSL|): 6.6613381477509392e-16
42 // max(|f - f_GSL| / |f_GSL|): 4.0617918857203532e-16
43 const testcase_comp_ellint_1<double>
44 data001[19] =
45 {
46 { 2.2805491384227703, -0.90000000000000002 },
47 { 1.9953027776647296, -0.80000000000000004 },
48 { 1.8456939983747236, -0.69999999999999996 },
49 { 1.7507538029157526, -0.59999999999999998 },
50 { 1.6857503548125963, -0.50000000000000000 },
51 { 1.6399998658645112, -0.40000000000000002 },
52 { 1.6080486199305128, -0.30000000000000004 },
53 { 1.5868678474541660, -0.19999999999999996 },
54 { 1.5747455615173562, -0.099999999999999978 },
55 { 1.5707963267948966, 0.0000000000000000 },
56 { 1.5747455615173562, 0.10000000000000009 },
57 { 1.5868678474541660, 0.19999999999999996 },
58 { 1.6080486199305128, 0.30000000000000004 },
59 { 1.6399998658645112, 0.39999999999999991 },
60 { 1.6857503548125963, 0.50000000000000000 },
61 { 1.7507538029157526, 0.60000000000000009 },
62 { 1.8456939983747236, 0.69999999999999996 },
63 { 1.9953027776647296, 0.80000000000000004 },
64 { 2.2805491384227703, 0.89999999999999991 },
65 };
66 const double toler001 = 2.5000000000000020e-13;
67
68 template<typename Tp, unsigned int Num>
69 void
70 test(const testcase_comp_ellint_1<Tp> (&data)[Num], Tp toler)
71 {
72 bool test __attribute__((unused)) = true;
73 const Tp eps = std::numeric_limits<Tp>::epsilon();
74 Tp max_abs_diff = -Tp(1);
75 Tp max_abs_frac = -Tp(1);
76 unsigned int num_datum = Num;
77 for (unsigned int i = 0; i < num_datum; ++i)
78 {
79 const Tp f = std::comp_ellint_1(data[i].k);
80 const Tp f0 = data[i].f0;
81 const Tp diff = f - f0;
82 if (std::abs(diff) > max_abs_diff)
83 max_abs_diff = std::abs(diff);
84 if (std::abs(f0) > Tp(10) * eps
85 && std::abs(f) > Tp(10) * eps)
86 {
87 const Tp frac = diff / f0;
88 if (std::abs(frac) > max_abs_frac)
89 max_abs_frac = std::abs(frac);
90 }
91 }
92 VERIFY(max_abs_frac < toler);
93 }
94
95 int
96 main()
97 {
98 test(data001, toler001);
99 return 0;
100 }