1 /* sys/test.c
2  *
3  * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or (at
8  * your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #include <config.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <gsl/gsl_math.h>
24 #include <gsl/gsl_test.h>
25 #include <gsl/gsl_ieee_utils.h>
26 
27 int
main(void)28 main (void)
29 {
30   double y, y_expected;
31   int e, e_expected;
32 
33   gsl_ieee_env_setup ();
34 
35   /* Test for expm1 */
36 
37   y = gsl_expm1 (0.0);
38   y_expected = 0.0;
39   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(0.0)");
40 
41   y = gsl_expm1 (1e-10);
42   y_expected = 1.000000000050000000002e-10;
43   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(1e-10)");
44 
45   y = gsl_expm1 (-1e-10);
46   y_expected = -9.999999999500000000017e-11;
47   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-1e-10)");
48 
49   y = gsl_expm1 (0.1);
50   y_expected = 0.1051709180756476248117078264902;
51   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(0.1)");
52 
53   y = gsl_expm1 (-0.1);
54   y_expected = -0.09516258196404042683575094055356;
55   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-0.1)");
56 
57   y = gsl_expm1 (10.0);
58   y_expected = 22025.465794806716516957900645284;
59   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(10.0)");
60 
61   y = gsl_expm1 (-10.0);
62   y_expected = -0.99995460007023751514846440848444;
63   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-10.0)");
64 
65   /* Test for log1p */
66 
67   y = gsl_log1p (0.0);
68   y_expected = 0.0;
69   gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(0.0)");
70 
71   y = gsl_log1p (1e-10);
72   y_expected = 9.9999999995000000000333333333308e-11;
73   gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(1e-10)");
74 
75   y = gsl_log1p (0.1);
76   y_expected = 0.095310179804324860043952123280765;
77   gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(0.1)");
78 
79   y = gsl_log1p (10.0);
80   y_expected = 2.3978952727983705440619435779651;
81   gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(10.0)");
82 
83   /* Test for gsl_hypot */
84 
85   y = gsl_hypot (0.0, 0.0);
86   y_expected = 0.0;
87   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(0.0, 0.0)");
88 
89   y = gsl_hypot (1e-10, 1e-10);
90   y_expected = 1.414213562373095048801688e-10;
91   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-10, 1e-10)");
92 
93   y = gsl_hypot (1e-38, 1e-38);
94   y_expected = 1.414213562373095048801688e-38;
95   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-38, 1e-38)");
96 
97   y = gsl_hypot (1e-10, -1.0);
98   y_expected = 1.000000000000000000005;
99   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-10, -1)");
100 
101   y = gsl_hypot (-1.0, 1e-10);
102   y_expected = 1.000000000000000000005;
103   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(-1, 1e-10)");
104 
105   y = gsl_hypot (1e307, 1e301);
106   y_expected = 1.000000000000499999999999e307;
107   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e307, 1e301)");
108 
109   y = gsl_hypot (1e301, 1e307);
110   y_expected = 1.000000000000499999999999e307;
111   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e301, 1e307)");
112 
113   y = gsl_hypot (1e307, 1e307);
114   y_expected = 1.414213562373095048801688e307;
115   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e307, 1e307)");
116 
117   /* Test +-Inf, finite */
118 
119   y = gsl_hypot (GSL_POSINF, 1.2);
120   y_expected = GSL_POSINF;
121   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_POSINF, 1.2)");
122 
123   y = gsl_hypot (GSL_NEGINF, 1.2);
124   y_expected = GSL_POSINF;
125   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_NEGINF, 1.2)");
126 
127   y = gsl_hypot (1.2, GSL_POSINF);
128   y_expected = GSL_POSINF;
129   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1.2, GSL_POSINF)");
130 
131   y = gsl_hypot (1.2, GSL_NEGINF);
132   y_expected = GSL_POSINF;
133   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1.2, GSL_NEGINF)");
134 
135   /* Test NaN, finite */
136 
137   y = gsl_hypot (GSL_NAN, 1.2);
138   y_expected = GSL_NAN;
139   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_NAN, 1.2)");
140 
141   y = gsl_hypot (1.2, GSL_NAN);
142   y_expected = GSL_NAN;
143   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1.2, GSL_NAN)");
144 
145   /* Test NaN, NaN */
146 
147   y = gsl_hypot (GSL_NAN, GSL_NAN);
148   y_expected = GSL_NAN;
149   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_NAN, GSL_NAN)");
150 
151   /* Test +Inf, NaN */
152 
153   y = gsl_hypot (GSL_POSINF, GSL_NAN);
154   y_expected = GSL_POSINF;
155   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_POSINF, GSL_NAN)");
156 
157   /* Test -Inf, NaN */
158 
159   y = gsl_hypot (GSL_NEGINF, GSL_NAN);
160   y_expected = GSL_POSINF;
161   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_NEGINF, GSL_NAN)");
162 
163   /* Test NaN, +Inf */
164 
165   y = gsl_hypot (GSL_NAN, GSL_POSINF);
166   y_expected = GSL_POSINF;
167   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_NAN, GSL_POSINF)");
168 
169   /* Test NaN, -Inf */
170 
171   y = gsl_hypot (GSL_NAN, GSL_NEGINF);
172   y_expected = GSL_POSINF;
173   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(GSL_NAN, GSL_NEGINF)");
174 
175   /* Test for gsl_hypot3 */
176 
177   y = gsl_hypot3 (0.0, 0.0, 0.0);
178   y_expected = 0.0;
179   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(0.0, 0.0, 0.0)");
180 
181   y = gsl_hypot3 (1e-10, 1e-10, 1e-10);
182   y_expected = 1.732050807568877293527446e-10;
183   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e-10, 1e-10, 1e-10)");
184 
185   y = gsl_hypot3 (1e-38, 1e-38, 1e-38);
186   y_expected = 1.732050807568877293527446e-38;
187   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e-38, 1e-38, 1e-38)");
188 
189   y = gsl_hypot3 (1e-10, 1e-10, -1.0);
190   y_expected = 1.000000000000000000099;
191   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e-10, 1e-10, -1)");
192 
193   y = gsl_hypot3 (1e-10, -1.0, 1e-10);
194   y_expected = 1.000000000000000000099;
195   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e-10, -1, 1e-10)");
196 
197   y = gsl_hypot3 (-1.0, 1e-10, 1e-10);
198   y_expected = 1.000000000000000000099;
199   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(-1, 1e-10, 1e-10)");
200 
201   y = gsl_hypot3 (1e307, 1e301, 1e301);
202   y_expected = 1.0000000000009999999999995e307;
203   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e307, 1e301, 1e301)");
204 
205   y = gsl_hypot3 (1e307, 1e307, 1e307);
206   y_expected = 1.732050807568877293527446e307;
207   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e307, 1e307, 1e307)");
208 
209   y = gsl_hypot3 (1e307, 1e-307, 1e-307);
210   y_expected = 1.0e307;
211   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot3(1e307, 1e-307, 1e-307)");
212 
213   /* Test for acosh */
214 
215   y = gsl_acosh (1.0);
216   y_expected = 0.0;
217   gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1.0)");
218 
219   y = gsl_acosh (1.1);
220   y_expected = 4.435682543851151891329110663525e-1;
221   gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1.1)");
222 
223   y = gsl_acosh (10.0);
224   y_expected = 2.9932228461263808979126677137742e0;
225   gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(10.0)");
226 
227   y = gsl_acosh (1e10);
228   y_expected = 2.3718998110500402149594646668302e1;
229   gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1e10)");
230 
231   /* Test for asinh */
232 
233   y = gsl_asinh (0.0);
234   y_expected = 0.0;
235   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(0.0)");
236 
237   y = gsl_asinh (1e-10);
238   y_expected = 9.9999999999999999999833333333346e-11;
239   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e-10)");
240 
241   y = gsl_asinh (-1e-10);
242   y_expected = -9.9999999999999999999833333333346e-11;
243   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e-10)");
244 
245   y = gsl_asinh (0.1);
246   y_expected = 9.983407889920756332730312470477e-2;
247   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(0.1)");
248 
249   y = gsl_asinh (-0.1);
250   y_expected = -9.983407889920756332730312470477e-2;
251   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-0.1)");
252 
253   y = gsl_asinh (1.0);
254   y_expected = 8.8137358701954302523260932497979e-1;
255   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1.0)");
256 
257   y = gsl_asinh (-1.0);
258   y_expected = -8.8137358701954302523260932497979e-1;
259   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-1.0)");
260 
261   y = gsl_asinh (10.0);
262   y_expected = 2.9982229502979697388465955375965e0;
263   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(10)");
264 
265   y = gsl_asinh (-10.0);
266   y_expected = -2.9982229502979697388465955375965e0;
267   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-10)");
268 
269   y = gsl_asinh (1e10);
270   y_expected = 2.3718998110500402149599646668302e1;
271   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e10)");
272 
273   y = gsl_asinh (-1e10);
274   y_expected = -2.3718998110500402149599646668302e1;
275   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-1e10)");
276 
277   /* Test for atanh */
278 
279   y = gsl_atanh (0.0);
280   y_expected = 0.0;
281   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.0)");
282 
283   y = gsl_atanh (1e-20);
284   y_expected = 1e-20;
285   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(1e-20)");
286 
287   y = gsl_atanh (-1e-20);
288   y_expected = -1e-20;
289   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(-1e-20)");
290 
291   y = gsl_atanh (0.1);
292   y_expected = 1.0033534773107558063572655206004e-1;
293   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.1)");
294 
295   y = gsl_atanh (-0.1);
296   y_expected = -1.0033534773107558063572655206004e-1;
297   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(-0.1)");
298 
299   y = gsl_atanh (0.9);
300   y_expected = 1.4722194895832202300045137159439e0;
301   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.9)");
302 
303   y = gsl_atanh (-0.9);
304   y_expected = -1.4722194895832202300045137159439e0;
305   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.9)");
306 
307   /* Test for pow_int */
308 
309   y = gsl_pow_2 (-3.14);
310   y_expected = pow (-3.14, 2.0);
311   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_2(-3.14)");
312 
313   y = gsl_pow_3 (-3.14);
314   y_expected = pow (-3.14, 3.0);
315   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_3(-3.14)");
316 
317   y = gsl_pow_4 (-3.14);
318   y_expected = pow (-3.14, 4.0);
319   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_4(-3.14)");
320 
321   y = gsl_pow_5 (-3.14);
322   y_expected = pow (-3.14, 5.0);
323   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_5(-3.14)");
324 
325   y = gsl_pow_6 (-3.14);
326   y_expected = pow (-3.14, 6.0);
327   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_6(-3.14)");
328 
329   y = gsl_pow_7 (-3.14);
330   y_expected = pow (-3.14, 7.0);
331   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_7(-3.14)");
332 
333   y = gsl_pow_8 (-3.14);
334   y_expected = pow (-3.14, 8.0);
335   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_8(-3.14)");
336 
337   y = gsl_pow_9 (-3.14);
338   y_expected = pow (-3.14, 9.0);
339   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_9(-3.14)");
340 
341   {
342     int n;
343     for (n = -9; n < 10; n++)
344       {
345         y = gsl_pow_int (-3.14, n);
346         y_expected = pow (-3.14, n);
347         gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_int(-3.14,%d)", n);
348       }
349   }
350 
351 
352   {
353     unsigned int n;
354     for (n = 0; n < 10; n++)
355       {
356         y = gsl_pow_uint (-3.14, n);
357         y_expected = pow (-3.14, n);
358         gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_uint(-3.14,%d)", n);
359       }
360   }
361 
362   /* Test case for n at INT_MAX, INT_MIN */
363 
364   {
365     double u = 1.0000001;
366     int n = INT_MAX;
367     y = gsl_pow_int (u, n);
368     y_expected = pow (u, n);
369     gsl_test_rel (y, y_expected, 1e-6, "gsl_pow_int(%.7f,%d)", u, n);
370 
371     n = INT_MIN;
372     y = gsl_pow_int (u, n);
373     y_expected = pow (u, n);
374     gsl_test_rel (y, y_expected, 1e-6, "gsl_pow_int(%.7f,%d)", u, n);
375   }
376 
377   /* Test for ldexp */
378 
379   y = gsl_ldexp (M_PI, -2);
380   y_expected = M_PI_4;
381   gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(pi,-2)");
382 
383   y = gsl_ldexp (1.0, 2);
384   y_expected = 4.000000;
385   gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(1.0,2)");
386 
387   y = gsl_ldexp (0.0, 2);
388   y_expected = 0.0;
389   gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(0.0,2)");
390 
391   y = gsl_ldexp (9.999999999999998890e-01, 1024);
392   y_expected = GSL_DBL_MAX;
393   gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp DBL_MAX");
394 
395   y = gsl_ldexp (1e308, -2000);
396   y_expected = 8.7098098162172166755761e-295;
397   gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(1e308,-2000)");
398 
399   y = gsl_ldexp (GSL_DBL_MIN, 2000);
400   y_expected = 2.554675596204441378334779940e294;
401   gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(DBL_MIN,2000)");
402 
403   /* Test subnormals */
404 
405   {
406     int i = 0;
407     volatile double x = GSL_DBL_MIN;
408     y_expected = 2.554675596204441378334779940e294;
409 
410     x /= 2;
411     while (x > 0)
412       {
413         i++ ;
414         y = gsl_ldexp (x, 2000 + i);
415         gsl_test_rel (y, y_expected, 1e-15, "gsl_ldexp(DBL_MIN/2**%d,%d)",i,2000+i);
416         x /= 2;
417       }
418   }
419 
420 
421   /* Test for frexp */
422 
423   y = gsl_frexp (0.0, &e);
424   y_expected = 0;
425   e_expected = 0;
426   gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(0) fraction");
427   gsl_test_int (e, e_expected, "gsl_frexp(0) exponent");
428 
429   y = gsl_frexp (M_PI, &e);
430   y_expected = M_PI_4;
431   e_expected = 2;
432   gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(pi) fraction");
433   gsl_test_int (e, e_expected, "gsl_frexp(pi) exponent");
434 
435   y = gsl_frexp (2.0, &e);
436   y_expected = 0.5;
437   e_expected = 2;
438   gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(2.0) fraction");
439   gsl_test_int (e, e_expected, "gsl_frexp(2.0) exponent");
440 
441   y = gsl_frexp (1.0 / 4.0, &e);
442   y_expected = 0.5;
443   e_expected = -1;
444   gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(0.25) fraction");
445   gsl_test_int (e, e_expected, "gsl_frexp(0.25) exponent");
446 
447   y = gsl_frexp (1.0 / 4.0 - 4.0 * GSL_DBL_EPSILON, &e);
448   y_expected = 0.999999999999996447;
449   e_expected = -2;
450   gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(0.25-eps) fraction");
451   gsl_test_int (e, e_expected, "gsl_frexp(0.25-eps) exponent");
452 
453   y = gsl_frexp (GSL_DBL_MAX, &e);
454   y_expected = 9.999999999999998890e-01;
455   e_expected = 1024;
456   gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(DBL_MAX) fraction");
457   gsl_test_int (e, e_expected, "gsl_frexp(DBL_MAX) exponent");
458 
459   y = gsl_frexp (-GSL_DBL_MAX, &e);
460   y_expected = -9.999999999999998890e-01;
461   e_expected = 1024;
462   gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(-DBL_MAX) fraction");
463   gsl_test_int (e, e_expected, "gsl_frexp(-DBL_MAX) exponent");
464 
465   y = gsl_frexp (GSL_DBL_MIN, &e);
466   y_expected = 0.5;
467   e_expected = -1021;
468   gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(DBL_MIN) fraction");
469   gsl_test_int (e, e_expected, "gsl_frexp(DBL_MIN) exponent");
470 
471   y = gsl_frexp (-GSL_DBL_MIN, &e);
472   y_expected = -0.5;
473   e_expected = -1021;
474   gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(-DBL_MIN) fraction");
475   gsl_test_int (e, e_expected, "gsl_frexp(-DBL_MIN) exponent");
476 
477   /* Test subnormals */
478 
479   {
480     int i = 0;
481     volatile double x = GSL_DBL_MIN;
482     y_expected = 0.5;
483     e_expected = -1021;
484 
485     x /= 2;
486 
487     while (x > 0)
488       {
489         e_expected--;
490         i++ ;
491 
492         y = gsl_frexp (x, &e);
493         gsl_test_rel (y, y_expected, 1e-15, "gsl_frexp(DBL_MIN/2**%d) fraction",i);
494         gsl_test_int (e, e_expected, "gsl_frexp(DBL_MIN/2**%d) exponent", i);
495         x /= 2;
496       }
497   }
498 
499 
500   /* Test for approximate floating point comparison */
501   {
502     double x, y;
503     int i;
504 
505     x = M_PI;
506     y = 22.0 / 7.0;
507 
508     /* test the basic function */
509 
510     for (i = 0; i < 10; i++)
511       {
512         double tol = pow (10, -i);
513         int res = gsl_fcmp (x, y, tol);
514         gsl_test_int (res, -(i >= 4), "gsl_fcmp(%.5f,%.5f,%g)", x, y, tol);
515       }
516 
517     for (i = 0; i < 10; i++)
518       {
519         double tol = pow (10, -i);
520         int res = gsl_fcmp (y, x, tol);
521         gsl_test_int (res, (i >= 4), "gsl_fcmp(%.5f,%.5f,%g)", y, x, tol);
522       }
523   }
524 
525 
526 #if HAVE_IEEE_COMPARISONS
527   /* Test for isinf, isnan, finite */
528 
529   {
530     double zero, one, inf, nan;
531     int s;
532 
533     zero = 0.0;
534     one = 1.0;
535     inf = exp (1.0e10);
536     nan = inf / inf;
537 
538     s = gsl_isinf (zero);
539     gsl_test_int (s, 0, "gsl_isinf(0)");
540 
541     s = gsl_isinf (one);
542     gsl_test_int (s, 0, "gsl_isinf(1)");
543 
544     s = gsl_isinf (inf);
545     gsl_test_int (s, 1, "gsl_isinf(inf)");
546 
547     s = gsl_isinf (-inf);
548     gsl_test_int (s, -1, "gsl_isinf(-inf)");
549 
550     s = gsl_isinf (nan);
551     gsl_test_int (s, 0, "gsl_isinf(nan)");
552 
553 
554     s = gsl_isnan (zero);
555     gsl_test_int (s, 0, "gsl_isnan(0)");
556 
557     s = gsl_isnan (one);
558     gsl_test_int (s, 0, "gsl_isnan(1)");
559 
560     s = gsl_isnan (inf);
561     gsl_test_int (s, 0, "gsl_isnan(inf)");
562 
563     s = gsl_isnan (-inf);
564     gsl_test_int (s, 0, "gsl_isnan(-inf)");
565 
566     s = gsl_isnan (nan) != 0;
567     gsl_test_int (s, 1, "gsl_isnan(nan)");
568 
569 
570     s = gsl_finite (zero);
571     gsl_test_int (s, 1, "gsl_finite(0)");
572 
573     s = gsl_finite (one);
574     gsl_test_int (s, 1, "gsl_finite(1)");
575 
576     s = gsl_finite (inf);
577     gsl_test_int (s, 0, "gsl_finite(inf)");
578 
579     s = gsl_finite (-inf);
580     gsl_test_int (s, 0, "gsl_finite(-inf)");
581 
582     s = gsl_finite (nan);
583     gsl_test_int (s, 0, "gsl_finite(nan)");
584   }
585 #endif
586 
587 
588   {
589     double x = gsl_fdiv (2.0, 3.0);
590     gsl_test_rel (x, 2.0 / 3.0, 4 * GSL_DBL_EPSILON, "gsl_fdiv(2,3)");
591   }
592 
593 
594   /* Test constants in gsl_math.h */
595 
596   {
597     double x = log(M_E);
598     gsl_test_rel (x, 1.0, 4 * GSL_DBL_EPSILON, "ln(M_E)");
599   }
600 
601   {
602     double x=pow(2.0,M_LOG2E);
603     gsl_test_rel (x, exp(1.0), 4 * GSL_DBL_EPSILON, "2^M_LOG2E");
604   }
605 
606   {
607     double x=pow(10.0,M_LOG10E);
608     gsl_test_rel (x, exp(1.0), 4 * GSL_DBL_EPSILON, "10^M_LOG10E");
609   }
610 
611   {
612     double x=pow(M_SQRT2, 2.0);
613     gsl_test_rel (x, 2.0, 4 * GSL_DBL_EPSILON, "M_SQRT2^2");
614   }
615 
616   {
617     double x=pow(M_SQRT1_2, 2.0);
618     gsl_test_rel (x, 1.0/2.0, 4 * GSL_DBL_EPSILON, "M_SQRT1_2");
619   }
620 
621   {
622     double x=pow(M_SQRT3, 2.0);
623     gsl_test_rel (x, 3.0, 4 * GSL_DBL_EPSILON, "M_SQRT3^2");
624   }
625 
626   {
627     double x = M_PI;
628     gsl_test_rel (x, 3.1415926535897932384626433832795, 4 * GSL_DBL_EPSILON, "M_PI");
629   }
630 
631   {
632     double x = 2 * M_PI_2;
633     gsl_test_rel (x, M_PI, 4 * GSL_DBL_EPSILON, "2*M_PI_2");
634   }
635 
636   {
637     double x = 4 * M_PI_4;
638     gsl_test_rel (x, M_PI, 4 * GSL_DBL_EPSILON, "4*M_PI_4");
639   }
640 
641   {
642     double x = pow(M_SQRTPI, 2.0);
643     gsl_test_rel (x, M_PI, 4 * GSL_DBL_EPSILON, "M_SQRTPI^2");
644   }
645 
646   {
647     double x = pow(M_2_SQRTPI, 2.0);
648     gsl_test_rel (x, 4/M_PI, 4 * GSL_DBL_EPSILON, "M_SQRTPI^2");
649   }
650 
651   {
652     double x = M_1_PI;
653     gsl_test_rel (x, 1/M_PI, 4 * GSL_DBL_EPSILON, "M_1_SQRTPI");
654   }
655 
656   {
657     double x = M_2_PI;
658     gsl_test_rel (x, 2.0/M_PI, 4 * GSL_DBL_EPSILON, "M_2_PI");
659   }
660 
661   {
662     double x = exp(M_LN10);
663     gsl_test_rel (x, 10, 4 * GSL_DBL_EPSILON, "exp(M_LN10)");
664   }
665 
666   {
667     double x = exp(M_LN2);
668     gsl_test_rel (x, 2, 4 * GSL_DBL_EPSILON, "exp(M_LN2)");
669   }
670 
671   {
672     double x = exp(M_LNPI);
673     gsl_test_rel (x, M_PI, 4 * GSL_DBL_EPSILON, "exp(M_LNPI)");
674   }
675 
676   {
677     double x = M_EULER;
678     gsl_test_rel (x, 0.5772156649015328606065120900824, 4 * GSL_DBL_EPSILON, "M_EULER");
679   }
680 
681   exit (gsl_test_summary ());
682 }
683