]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/special_functions/17_legendre/check_value.cc
1 // { dg-do run { target c++11 } }
2 // { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__" }
4 // Copyright (C) 2016-2017 Free Software Foundation, Inc.
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)
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.
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/>.
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/
26 #if defined(__TEST_DEBUG)
31 std::cout << "line " << __LINE__ \
32 << " max_abs_frac = " << max_abs_frac \
36 # include <testsuite_hooks.h>
38 #include <specfun_testcase.h>
42 // max(|f - f_GSL|): 0.0000000000000000
43 // max(|f - f_GSL| / |f_GSL|): 0.0000000000000000
44 const testcase_legendre
<double>
47 { 1.0000000000000000, 0, -1.0000000000000000 },
48 { 1.0000000000000000, 0, -0.90000000000000002 },
49 { 1.0000000000000000, 0, -0.80000000000000004 },
50 { 1.0000000000000000, 0, -0.69999999999999996 },
51 { 1.0000000000000000, 0, -0.59999999999999998 },
52 { 1.0000000000000000, 0, -0.50000000000000000 },
53 { 1.0000000000000000, 0, -0.40000000000000002 },
54 { 1.0000000000000000, 0, -0.30000000000000004 },
55 { 1.0000000000000000, 0, -0.19999999999999996 },
56 { 1.0000000000000000, 0, -0.099999999999999978 },
57 { 1.0000000000000000, 0, 0.0000000000000000 },
58 { 1.0000000000000000, 0, 0.10000000000000009 },
59 { 1.0000000000000000, 0, 0.19999999999999996 },
60 { 1.0000000000000000, 0, 0.30000000000000004 },
61 { 1.0000000000000000, 0, 0.39999999999999991 },
62 { 1.0000000000000000, 0, 0.50000000000000000 },
63 { 1.0000000000000000, 0, 0.60000000000000009 },
64 { 1.0000000000000000, 0, 0.69999999999999996 },
65 { 1.0000000000000000, 0, 0.80000000000000004 },
66 { 1.0000000000000000, 0, 0.89999999999999991 },
67 { 1.0000000000000000, 0, 1.0000000000000000 },
69 const double toler001
= 2.5000000000000020e-13;
72 // max(|f - f_GSL|): 0.0000000000000000
73 // max(|f - f_GSL| / |f_GSL|): 0.0000000000000000
74 const testcase_legendre
<double>
77 { -1.0000000000000000, 1, -1.0000000000000000 },
78 { -0.90000000000000002, 1, -0.90000000000000002 },
79 { -0.80000000000000004, 1, -0.80000000000000004 },
80 { -0.69999999999999996, 1, -0.69999999999999996 },
81 { -0.59999999999999998, 1, -0.59999999999999998 },
82 { -0.50000000000000000, 1, -0.50000000000000000 },
83 { -0.40000000000000002, 1, -0.40000000000000002 },
84 { -0.30000000000000004, 1, -0.30000000000000004 },
85 { -0.19999999999999996, 1, -0.19999999999999996 },
86 { -0.099999999999999978, 1, -0.099999999999999978 },
87 { 0.0000000000000000, 1, 0.0000000000000000 },
88 { 0.10000000000000009, 1, 0.10000000000000009 },
89 { 0.19999999999999996, 1, 0.19999999999999996 },
90 { 0.30000000000000004, 1, 0.30000000000000004 },
91 { 0.39999999999999991, 1, 0.39999999999999991 },
92 { 0.50000000000000000, 1, 0.50000000000000000 },
93 { 0.60000000000000009, 1, 0.60000000000000009 },
94 { 0.69999999999999996, 1, 0.69999999999999996 },
95 { 0.80000000000000004, 1, 0.80000000000000004 },
96 { 0.89999999999999991, 1, 0.89999999999999991 },
97 { 1.0000000000000000, 1, 1.0000000000000000 },
99 const double toler002
= 2.5000000000000020e-13;
101 // Test data for l=2.
102 // max(|f - f_GSL|): 1.1102230246251565e-16
103 // max(|f - f_GSL| / |f_GSL|): 1.3877787807814482e-15
104 const testcase_legendre
<double>
107 { 1.0000000000000000, 2, -1.0000000000000000 },
108 { 0.71500000000000008, 2, -0.90000000000000002 },
109 { 0.46000000000000019, 2, -0.80000000000000004 },
110 { 0.23499999999999988, 2, -0.69999999999999996 },
111 { 0.039999999999999925, 2, -0.59999999999999998 },
112 { -0.12500000000000000, 2, -0.50000000000000000 },
113 { -0.25999999999999995, 2, -0.40000000000000002 },
114 { -0.36499999999999999, 2, -0.30000000000000004 },
115 { -0.44000000000000006, 2, -0.19999999999999996 },
116 { -0.48499999999999999, 2, -0.099999999999999978 },
117 { -0.50000000000000000, 2, 0.0000000000000000 },
118 { -0.48499999999999999, 2, 0.10000000000000009 },
119 { -0.44000000000000006, 2, 0.19999999999999996 },
120 { -0.36499999999999999, 2, 0.30000000000000004 },
121 { -0.26000000000000012, 2, 0.39999999999999991 },
122 { -0.12500000000000000, 2, 0.50000000000000000 },
123 { 0.040000000000000147, 2, 0.60000000000000009 },
124 { 0.23499999999999988, 2, 0.69999999999999996 },
125 { 0.46000000000000019, 2, 0.80000000000000004 },
126 { 0.71499999999999986, 2, 0.89999999999999991 },
127 { 1.0000000000000000, 2, 1.0000000000000000 },
129 const double toler003
= 2.5000000000000020e-13;
131 // Test data for l=5.
132 // max(|f - f_GSL|): 2.0122792321330962e-16
133 // max(|f - f_GSL| / |f_GSL|): 4.8911475274404243e-15
134 const testcase_legendre
<double>
137 { -1.0000000000000000, 5, -1.0000000000000000 },
138 { 0.041141250000000087, 5, -0.90000000000000002 },
139 { 0.39951999999999993, 5, -0.80000000000000004 },
140 { 0.36519874999999991, 5, -0.69999999999999996 },
141 { 0.15263999999999994, 5, -0.59999999999999998 },
142 { -0.089843750000000000, 5, -0.50000000000000000 },
143 { -0.27063999999999994, 5, -0.40000000000000002 },
144 { -0.34538625000000001, 5, -0.30000000000000004 },
145 { -0.30751999999999996, 5, -0.19999999999999996 },
146 { -0.17882874999999995, 5, -0.099999999999999978 },
147 { 0.0000000000000000, 5, 0.0000000000000000 },
148 { 0.17882875000000015, 5, 0.10000000000000009 },
149 { 0.30751999999999996, 5, 0.19999999999999996 },
150 { 0.34538625000000001, 5, 0.30000000000000004 },
151 { 0.27064000000000010, 5, 0.39999999999999991 },
152 { 0.089843750000000000, 5, 0.50000000000000000 },
153 { -0.15264000000000016, 5, 0.60000000000000009 },
154 { -0.36519874999999991, 5, 0.69999999999999996 },
155 { -0.39951999999999993, 5, 0.80000000000000004 },
156 { -0.041141250000000261, 5, 0.89999999999999991 },
157 { 1.0000000000000000, 5, 1.0000000000000000 },
159 const double toler004
= 2.5000000000000020e-13;
161 // Test data for l=10.
162 // max(|f - f_GSL|): 2.7755575615628914e-16
163 // max(|f - f_GSL| / |f_GSL|): 1.0547610802636413e-15
164 const testcase_legendre
<double>
167 { 1.0000000000000000, 10, -1.0000000000000000 },
168 { -0.26314561785585960, 10, -0.90000000000000002 },
169 { 0.30052979560000004, 10, -0.80000000000000004 },
170 { 0.085805795531640333, 10, -0.69999999999999996 },
171 { -0.24366274560000001, 10, -0.59999999999999998 },
172 { -0.18822860717773438, 10, -0.50000000000000000 },
173 { 0.096839064399999925, 10, -0.40000000000000002 },
174 { 0.25147634951601561, 10, -0.30000000000000004 },
175 { 0.12907202559999983, 10, -0.19999999999999996 },
176 { -0.12212499738710943, 10, -0.099999999999999978 },
177 { -0.24609375000000000, 10, 0.0000000000000000 },
178 { -0.12212499738710922, 10, 0.10000000000000009 },
179 { 0.12907202559999983, 10, 0.19999999999999996 },
180 { 0.25147634951601561, 10, 0.30000000000000004 },
181 { 0.096839064400000258, 10, 0.39999999999999991 },
182 { -0.18822860717773438, 10, 0.50000000000000000 },
183 { -0.24366274559999984, 10, 0.60000000000000009 },
184 { 0.085805795531640333, 10, 0.69999999999999996 },
185 { 0.30052979560000004, 10, 0.80000000000000004 },
186 { -0.26314561785585899, 10, 0.89999999999999991 },
187 { 1.0000000000000000, 10, 1.0000000000000000 },
189 const double toler005
= 2.5000000000000020e-13;
191 // Test data for l=20.
192 // max(|f - f_GSL|): 3.3306690738754696e-16
193 // max(|f - f_GSL| / |f_GSL|): 2.2307336678138069e-15
194 const testcase_legendre
<double>
197 { 1.0000000000000000, 20, -1.0000000000000000 },
198 { -0.14930823530984835, 20, -0.90000000000000002 },
199 { 0.22420460541741347, 20, -0.80000000000000004 },
200 { -0.20457394463834172, 20, -0.69999999999999996 },
201 { 0.15916752910098109, 20, -0.59999999999999998 },
202 { -0.048358381067373557, 20, -0.50000000000000000 },
203 { -0.10159261558628156, 20, -0.40000000000000002 },
204 { 0.18028715947998042, 20, -0.30000000000000004 },
205 { -0.098042194344594796, 20, -0.19999999999999996 },
206 { -0.082077130944527663, 20, -0.099999999999999978 },
207 { 0.17619705200195312, 20, 0.0000000000000000 },
208 { -0.082077130944528023, 20, 0.10000000000000009 },
209 { -0.098042194344594796, 20, 0.19999999999999996 },
210 { 0.18028715947998042, 20, 0.30000000000000004 },
211 { -0.10159261558628112, 20, 0.39999999999999991 },
212 { -0.048358381067373557, 20, 0.50000000000000000 },
213 { 0.15916752910098075, 20, 0.60000000000000009 },
214 { -0.20457394463834172, 20, 0.69999999999999996 },
215 { 0.22420460541741347, 20, 0.80000000000000004 },
216 { -0.14930823530984924, 20, 0.89999999999999991 },
217 { 1.0000000000000000, 20, 1.0000000000000000 },
219 const double toler006
= 2.5000000000000020e-13;
221 // Test data for l=50.
222 // max(|f - f_GSL|): 3.6082248300317588e-16
223 // max(|f - f_GSL| / |f_GSL|): 2.1700196856209138e-15
224 const testcase_legendre
<double>
227 { 1.0000000000000000, 50, -1.0000000000000000 },
228 { -0.17003765994383671, 50, -0.90000000000000002 },
229 { 0.13879737345093113, 50, -0.80000000000000004 },
230 { -0.014572731645892852, 50, -0.69999999999999996 },
231 { -0.058860798844002096, 50, -0.59999999999999998 },
232 { -0.031059099239609811, 50, -0.50000000000000000 },
233 { 0.041569033381825375, 50, -0.40000000000000002 },
234 { 0.10911051574714797, 50, -0.30000000000000004 },
235 { 0.083432272204197494, 50, -0.19999999999999996 },
236 { -0.038205812661313600, 50, -0.099999999999999978 },
237 { -0.11227517265921705, 50, 0.0000000000000000 },
238 { -0.038205812661314155, 50, 0.10000000000000009 },
239 { 0.083432272204197494, 50, 0.19999999999999996 },
240 { 0.10911051574714797, 50, 0.30000000000000004 },
241 { 0.041569033381824674, 50, 0.39999999999999991 },
242 { -0.031059099239609811, 50, 0.50000000000000000 },
243 { -0.058860798844001430, 50, 0.60000000000000009 },
244 { -0.014572731645892852, 50, 0.69999999999999996 },
245 { 0.13879737345093113, 50, 0.80000000000000004 },
246 { -0.17003765994383657, 50, 0.89999999999999991 },
247 { 1.0000000000000000, 50, 1.0000000000000000 },
249 const double toler007
= 2.5000000000000020e-13;
251 // Test data for l=100.
252 // max(|f - f_GSL|): 3.4694469519536142e-16
253 // max(|f - f_GSL| / |f_GSL|): 6.8214063779431592e-15
254 const testcase_legendre
<double>
257 { 1.0000000000000000, 100, -1.0000000000000000 },
258 { 0.10226582055871893, 100, -0.90000000000000002 },
259 { 0.050861167913584228, 100, -0.80000000000000004 },
260 { -0.077132507199778641, 100, -0.69999999999999996 },
261 { -0.023747023905133141, 100, -0.59999999999999998 },
262 { -0.060518025961861198, 100, -0.50000000000000000 },
263 { -0.072258202125684470, 100, -0.40000000000000002 },
264 { 0.057127392202801566, 100, -0.30000000000000004 },
265 { 0.014681835355659706, 100, -0.19999999999999996 },
266 { -0.063895098434750205, 100, -0.099999999999999978 },
267 { 0.079589237387178727, 100, 0.0000000000000000 },
268 { -0.063895098434749761, 100, 0.10000000000000009 },
269 { 0.014681835355659706, 100, 0.19999999999999996 },
270 { 0.057127392202801566, 100, 0.30000000000000004 },
271 { -0.072258202125685025, 100, 0.39999999999999991 },
272 { -0.060518025961861198, 100, 0.50000000000000000 },
273 { -0.023747023905134217, 100, 0.60000000000000009 },
274 { -0.077132507199778641, 100, 0.69999999999999996 },
275 { 0.050861167913584228, 100, 0.80000000000000004 },
276 { 0.10226582055871711, 100, 0.89999999999999991 },
277 { 1.0000000000000000, 100, 1.0000000000000000 },
279 const double toler008
= 5.0000000000000039e-13;
281 template<typename Tp
, unsigned int Num
>
283 test(const testcase_legendre
<Tp
> (&data
)[Num
], Tp toler
)
285 const Tp eps
= std::numeric_limits
<Tp
>::epsilon();
286 Tp max_abs_diff
= -Tp(1);
287 Tp max_abs_frac
= -Tp(1);
288 unsigned int num_datum
= Num
;
289 for (unsigned int i
= 0; i
< num_datum
; ++i
)
291 const Tp f
= std::legendre(data
[i
].l
, data
[i
].x
);
292 const Tp f0
= data
[i
].f0
;
293 const Tp diff
= f
- f0
;
294 if (std::abs(diff
) > max_abs_diff
)
295 max_abs_diff
= std::abs(diff
);
296 if (std::abs(f0
) > Tp(10) * eps
297 && std::abs(f
) > Tp(10) * eps
)
299 const Tp frac
= diff
/ f0
;
300 if (std::abs(frac
) > max_abs_frac
)
301 max_abs_frac
= std::abs(frac
);
304 VERIFY(max_abs_frac
< toler
);
310 test(data001
, toler001
);
311 test(data002
, toler002
);
312 test(data003
, toler003
);
313 test(data004
, toler004
);
314 test(data005
, toler005
);
315 test(data006
, toler006
);
316 test(data007
, toler007
);
317 test(data008
, toler008
);