1 /* sys/infnan.c
2 *
3 * Copyright (C) 2001 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 2 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., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <config.h>
21 #include <math.h>
22
23 double gsl_nan (void);
24 double gsl_posinf (void);
25 double gsl_neginf (void);
26 double gsl_fdiv (const double x, const double y);
27
gsl_nan(void)28 double gsl_nan (void)
29 {
30 return gsl_fdiv (0.0, 0.0);
31 }
32
gsl_posinf(void)33 double gsl_posinf (void)
34 {
35 return gsl_fdiv (+1.0, 0.0);
36 }
37
gsl_neginf(void)38 double gsl_neginf (void)
39 {
40 return gsl_fdiv (-1.0, 0.0);
41 }
42
43
44 int gsl_isnan (const double x);
45 int gsl_isinf (const double x);
46 int gsl_finite (const double x);
47
48 #if defined(_MSC_VER) /* Microsoft Visual C++ */
49 #include <float.h>
50 int
gsl_isnan(const double x)51 gsl_isnan (const double x)
52 {
53 return _isnan(x);
54 }
55
56 int
gsl_isinf(const double x)57 gsl_isinf (const double x)
58 {
59 int fpc = _fpclass(x);
60
61 if (fpc == _FPCLASS_PINF)
62 return +1;
63 else if (fpc == _FPCLASS_NINF)
64 return -1;
65 else
66 return 0;
67 }
68
69 int
gsl_finite(const double x)70 gsl_finite (const double x)
71 {
72 return _finite(x);
73 }
74 #elif HAVE_IEEE_COMPARISONS
75 int
gsl_isnan(const double x)76 gsl_isnan (const double x)
77 {
78 int status = (x != x);
79 return status;
80 }
81
82 int
gsl_isinf(const double x)83 gsl_isinf (const double x)
84 {
85 double y = x - x;
86 int s = (y != y);
87
88 if (s && x > 0)
89 return +1;
90 else if (s && x < 0)
91 return -1;
92 else
93 return 0;
94 }
95
96 int
gsl_finite(const double x)97 gsl_finite (const double x)
98 {
99 const double y = x - x;
100 int status = (y == y);
101 return status;
102 }
103 #else
104
105 #if HAVE_DECL_ISNAN
106 int
gsl_isnan(const double x)107 gsl_isnan (const double x)
108 {
109 return isnan(x);
110 }
111 #endif
112
113 #if HAVE_DECL_ISINF
114 int
gsl_isinf(const double x)115 gsl_isinf (const double x)
116 {
117 return isinf(x);
118 }
119 #endif
120
121 #if HAVE_DECL_FINITE
122 int
gsl_finite(const double x)123 gsl_finite (const double x)
124 {
125 return finite(x);
126 }
127 #elif HAVE_DECL_ISFINITE
128 int
gsl_finite(const double x)129 gsl_finite (const double x)
130 {
131 return isfinite(x);
132 }
133 #endif
134
135 #endif
136
137