]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/special_functions/03_beta/check_value.cc
Only run math special function tests for C++11 and later
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / special_functions / 03_beta / check_value.cc
1 // { dg-do run { target c++11 } }
2 // { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__" }
3 //
4 // Copyright (C) 2016 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.
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
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
20
21 // beta
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
41 // Test data for x=10.000000000000000.
42 // max(|f - f_GSL|): 2.1175823681357508e-21
43 // max(|f - f_GSL| / |f_GSL|): 9.9466182377295583e-14
44 const testcase_beta<double>
45 data001[10] =
46 {
47 { 1.0825088224469029e-06, 10.000000000000000, 10.000000000000000 },
48 { 4.9925087406346778e-09, 10.000000000000000, 20.000000000000000 },
49 { 1.5729567312509485e-10, 10.000000000000000, 30.000000000000000 },
50 { 1.2168673582561288e-11, 10.000000000000000, 40.000000000000000 },
51 { 1.5916380099863291e-12, 10.000000000000000, 50.000000000000000 },
52 { 2.9408957938463963e-13, 10.000000000000000, 60.000000000000000 },
53 { 6.9411637980691676e-14, 10.000000000000000, 70.000000000000000 },
54 { 1.9665612972502651e-14, 10.000000000000000, 80.000000000000000 },
55 { 6.4187824828154399e-15, 10.000000000000000, 90.000000000000000 },
56 { 2.3455339739604842e-15, 10.000000000000000, 100.00000000000000 },
57 };
58 const double toler001 = 5.0000000000000029e-12;
59
60 // Test data for x=20.000000000000000.
61 // max(|f - f_GSL|): 1.9025154088719637e-23
62 // max(|f - f_GSL| / |f_GSL|): 3.8107402664859521e-15
63 const testcase_beta<double>
64 data002[10] =
65 {
66 { 4.9925087406346778e-09, 20.000000000000000, 10.000000000000000 },
67 { 7.2544445519248436e-13, 20.000000000000000, 20.000000000000000 },
68 { 1.7681885473062028e-15, 20.000000000000000, 30.000000000000000 },
69 { 1.7891885039182335e-17, 20.000000000000000, 40.000000000000000 },
70 { 4.3240677875623635e-19, 20.000000000000000, 50.000000000000000 },
71 { 1.8857342309689050e-20, 20.000000000000000, 60.000000000000000 },
72 { 1.2609804003539998e-21, 20.000000000000000, 70.000000000000000 },
73 { 1.1660809542079041e-22, 20.000000000000000, 80.000000000000000 },
74 { 1.3907944279729071e-23, 20.000000000000000, 90.000000000000000 },
75 { 2.0365059099917614e-24, 20.000000000000000, 100.00000000000000 },
76 };
77 const double toler002 = 2.5000000000000020e-13;
78
79 // Test data for x=30.000000000000000.
80 // max(|f - f_GSL|): 9.0472879497987402e-25
81 // max(|f - f_GSL| / |f_GSL|): 5.7517716603708290e-15
82 const testcase_beta<double>
83 data003[10] =
84 {
85 { 1.5729567312509485e-10, 30.000000000000000, 10.000000000000000 },
86 { 1.7681885473062028e-15, 30.000000000000000, 20.000000000000000 },
87 { 5.6370779640482451e-19, 30.000000000000000, 30.000000000000000 },
88 { 1.0539424603796547e-21, 30.000000000000000, 40.000000000000000 },
89 { 6.0118197777273836e-24, 30.000000000000000, 50.000000000000000 },
90 { 7.4279528553260165e-26, 30.000000000000000, 60.000000000000000 },
91 { 1.6212207780604767e-27, 30.000000000000000, 70.000000000000000 },
92 { 5.4783729715317616e-29, 30.000000000000000, 80.000000000000000 },
93 { 2.6183005659681346e-30, 30.000000000000000, 90.000000000000000 },
94 { 1.6587948222122229e-31, 30.000000000000000, 100.00000000000000 },
95 };
96 const double toler003 = 5.0000000000000039e-13;
97
98 // Test data for x=40.000000000000000.
99 // max(|f - f_GSL|): 2.6495628995839168e-25
100 // max(|f - f_GSL| / |f_GSL|): 2.1773637706750213e-14
101 const testcase_beta<double>
102 data004[10] =
103 {
104 { 1.2168673582561288e-11, 40.000000000000000, 10.000000000000000 },
105 { 1.7891885039182335e-17, 40.000000000000000, 20.000000000000000 },
106 { 1.0539424603796547e-21, 40.000000000000000, 30.000000000000000 },
107 { 4.6508509140090659e-25, 40.000000000000000, 40.000000000000000 },
108 { 7.5161712118557719e-28, 40.000000000000000, 50.000000000000000 },
109 { 3.0311331979886071e-30, 40.000000000000000, 60.000000000000000 },
110 { 2.4175035070466313e-32, 40.000000000000000, 70.000000000000000 },
111 { 3.2734839142758369e-34, 40.000000000000000, 80.000000000000000 },
112 { 6.7690629601315579e-36, 40.000000000000000, 90.000000000000000 },
113 { 1.9797337118812366e-37, 40.000000000000000, 100.00000000000000 },
114 };
115 const double toler004 = 2.5000000000000015e-12;
116
117 // Test data for x=50.000000000000000.
118 // max(|f - f_GSL|): 2.4603755039546938e-32
119 // max(|f - f_GSL| / |f_GSL|): 0.0000000000000000
120 const testcase_beta<double>
121 data005[10] =
122 {
123 { 1.5916380099863291e-12, 50.000000000000000, 10.000000000000000 },
124 { 4.3240677875623635e-19, 50.000000000000000, 20.000000000000000 },
125 { 6.0118197777273836e-24, 50.000000000000000, 30.000000000000000 },
126 { 7.5161712118557719e-28, 50.000000000000000, 40.000000000000000 },
127 { 3.9646612085674138e-31, 50.000000000000000, 50.000000000000000 },
128 { 5.8425643906418403e-34, 50.000000000000000, 60.000000000000000 },
129 { 1.8672362180783552e-36, 50.000000000000000, 70.000000000000000 },
130 { 1.0939382296458962e-38, 50.000000000000000, 80.000000000000000 },
131 { 1.0442781609881063e-40, 50.000000000000000, 90.000000000000000 },
132 { 1.4904121110954370e-42, 50.000000000000000, 100.00000000000000 },
133 };
134 const double toler005 = 2.5000000000000020e-13;
135
136 // Test data for x=60.000000000000000.
137 // max(|f - f_GSL|): 2.1911400503418824e-26
138 // max(|f - f_GSL| / |f_GSL|): 7.4505871813842522e-14
139 const testcase_beta<double>
140 data006[10] =
141 {
142 { 2.9408957938463963e-13, 60.000000000000000, 10.000000000000000 },
143 { 1.8857342309689050e-20, 60.000000000000000, 20.000000000000000 },
144 { 7.4279528553260165e-26, 60.000000000000000, 30.000000000000000 },
145 { 3.0311331979886071e-30, 60.000000000000000, 40.000000000000000 },
146 { 5.8425643906418403e-34, 60.000000000000000, 50.000000000000000 },
147 { 3.4501231469782229e-37, 60.000000000000000, 60.000000000000000 },
148 { 4.7706855386086599e-40, 60.000000000000000, 70.000000000000000 },
149 { 1.2902663809722593e-42, 60.000000000000000, 80.000000000000000 },
150 { 6.0105571058570508e-45, 60.000000000000000, 90.000000000000000 },
151 { 4.3922898898347209e-47, 60.000000000000000, 100.00000000000000 },
152 };
153 const double toler006 = 5.0000000000000029e-12;
154
155 // Test data for x=70.000000000000000.
156 // max(|f - f_GSL|): 6.9041106424942953e-27
157 // max(|f - f_GSL| / |f_GSL|): 9.9466182377295583e-14
158 const testcase_beta<double>
159 data007[10] =
160 {
161 { 6.9411637980691676e-14, 70.000000000000000, 10.000000000000000 },
162 { 1.2609804003539998e-21, 70.000000000000000, 20.000000000000000 },
163 { 1.6212207780604767e-27, 70.000000000000000, 30.000000000000000 },
164 { 2.4175035070466313e-32, 70.000000000000000, 40.000000000000000 },
165 { 1.8672362180783552e-36, 70.000000000000000, 50.000000000000000 },
166 { 4.7706855386086599e-40, 70.000000000000000, 60.000000000000000 },
167 { 3.0453137143486369e-43, 70.000000000000000, 70.000000000000000 },
168 { 4.0192274082013779e-46, 70.000000000000000, 80.000000000000000 },
169 { 9.5865870063501807e-49, 70.000000000000000, 90.000000000000000 },
170 { 3.7409127305819802e-51, 70.000000000000000, 100.00000000000000 },
171 };
172 const double toler007 = 5.0000000000000029e-12;
173
174 // Test data for x=80.000000000000000.
175 // max(|f - f_GSL|): 1.6786960063103131e-27
176 // max(|f - f_GSL| / |f_GSL|): 8.5361997546557118e-14
177 const testcase_beta<double>
178 data008[10] =
179 {
180 { 1.9665612972502651e-14, 80.000000000000000, 10.000000000000000 },
181 { 1.1660809542079041e-22, 80.000000000000000, 20.000000000000000 },
182 { 5.4783729715317616e-29, 80.000000000000000, 30.000000000000000 },
183 { 3.2734839142758369e-34, 80.000000000000000, 40.000000000000000 },
184 { 1.0939382296458962e-38, 80.000000000000000, 50.000000000000000 },
185 { 1.2902663809722593e-42, 80.000000000000000, 60.000000000000000 },
186 { 4.0192274082013779e-46, 80.000000000000000, 70.000000000000000 },
187 { 2.7160590828669411e-49, 80.000000000000000, 80.000000000000000 },
188 { 3.4593773902125368e-52, 80.000000000000000, 90.000000000000000 },
189 { 7.4807039968503468e-55, 80.000000000000000, 100.00000000000000 },
190 };
191 const double toler008 = 5.0000000000000029e-12;
192
193 // Test data for x=90.000000000000000.
194 // max(|f - f_GSL|): 2.7373473411169110e-28
195 // max(|f - f_GSL| / |f_GSL|): 4.2645896608047095e-14
196 const testcase_beta<double>
197 data009[10] =
198 {
199 { 6.4187824828154399e-15, 90.000000000000000, 10.000000000000000 },
200 { 1.3907944279729071e-23, 90.000000000000000, 20.000000000000000 },
201 { 2.6183005659681346e-30, 90.000000000000000, 30.000000000000000 },
202 { 6.7690629601315579e-36, 90.000000000000000, 40.000000000000000 },
203 { 1.0442781609881063e-40, 90.000000000000000, 50.000000000000000 },
204 { 6.0105571058570508e-45, 90.000000000000000, 60.000000000000000 },
205 { 9.5865870063501807e-49, 90.000000000000000, 70.000000000000000 },
206 { 3.4593773902125368e-52, 90.000000000000000, 80.000000000000000 },
207 { 2.4416737907558032e-55, 90.000000000000000, 90.000000000000000 },
208 { 3.0238531916564246e-58, 90.000000000000000, 100.00000000000000 },
209 };
210 const double toler009 = 2.5000000000000015e-12;
211
212 // Test data for x=100.00000000000000.
213 // max(|f - f_GSL|): 1.6960509462251754e-29
214 // max(|f - f_GSL| / |f_GSL|): 7.2309800883478868e-15
215 const testcase_beta<double>
216 data010[10] =
217 {
218 { 2.3455339739604842e-15, 100.00000000000000, 10.000000000000000 },
219 { 2.0365059099917614e-24, 100.00000000000000, 20.000000000000000 },
220 { 1.6587948222122229e-31, 100.00000000000000, 30.000000000000000 },
221 { 1.9797337118812366e-37, 100.00000000000000, 40.000000000000000 },
222 { 1.4904121110954370e-42, 100.00000000000000, 50.000000000000000 },
223 { 4.3922898898347209e-47, 100.00000000000000, 60.000000000000000 },
224 { 3.7409127305819802e-51, 100.00000000000000, 70.000000000000000 },
225 { 7.4807039968503468e-55, 100.00000000000000, 80.000000000000000 },
226 { 3.0238531916564246e-58, 100.00000000000000, 90.000000000000000 },
227 { 2.2087606931991853e-61, 100.00000000000000, 100.00000000000000 },
228 };
229 const double toler010 = 5.0000000000000039e-13;
230
231 template<typename Tp, unsigned int Num>
232 void
233 test(const testcase_beta<Tp> (&data)[Num], Tp toler)
234 {
235 bool test __attribute__((unused)) = true;
236 const Tp eps = std::numeric_limits<Tp>::epsilon();
237 Tp max_abs_diff = -Tp(1);
238 Tp max_abs_frac = -Tp(1);
239 unsigned int num_datum = Num;
240 for (unsigned int i = 0; i < num_datum; ++i)
241 {
242 const Tp f = std::beta(data[i].x, data[i].y);
243 const Tp f0 = data[i].f0;
244 const Tp diff = f - f0;
245 if (std::abs(diff) > max_abs_diff)
246 max_abs_diff = std::abs(diff);
247 if (std::abs(f0) > Tp(10) * eps
248 && std::abs(f) > Tp(10) * eps)
249 {
250 const Tp frac = diff / f0;
251 if (std::abs(frac) > max_abs_frac)
252 max_abs_frac = std::abs(frac);
253 }
254 }
255 VERIFY(max_abs_frac < toler);
256 }
257
258 int
259 main()
260 {
261 test(data001, toler001);
262 test(data002, toler002);
263 test(data003, toler003);
264 test(data004, toler004);
265 test(data005, toler005);
266 test(data006, toler006);
267 test(data007, toler007);
268 test(data008, toler008);
269 test(data009, toler009);
270 test(data010, toler010);
271 return 0;
272 }