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