* include/ruby/encoding.h (rb_econv_check_error): declared.
[ruby-svn.git] / missing / isinf.c
blob4aef51b213d365d6e8b27772556119ddebb9ff84
1 /* public domain rewrite of isinf(3) */
3 #ifdef __osf__
5 #define _IEEE 1
6 #include <nan.h>
8 int
9 isinf(double n)
11 if (IsNANorINF(n) && IsINF(n)) {
12 return 1;
14 else {
15 return 0;
19 #else
21 #include "ruby/config.h"
23 #if defined(HAVE_FINITE) && defined(HAVE_ISNAN)
25 #include <math.h>
26 #ifdef HAVE_IEEEFP_H
27 #include <ieeefp.h>
28 #endif
30 /*
31 * isinf may be provided only as a macro.
32 * ex. HP-UX, Solaris 10
33 * http://www.gnu.org/software/automake/manual/autoconf/Function-Portability.html
35 #ifndef isinf
36 int
37 isinf(double n)
39 return (!finite(n) && !isnan(n));
41 #endif
43 #else
45 #ifdef HAVE_STRING_H
46 # include <string.h>
47 #else
48 # include <strings.h>
49 #endif
51 static double zero(void) { return 0.0; }
52 static double one (void) { return 1.0; }
53 static double inf (void) { return one() / zero(); }
55 int
56 isinf(double n)
58 static double pinf = 0.0;
59 static double ninf = 0.0;
61 if (pinf == 0.0) {
62 pinf = inf();
63 ninf = -pinf;
65 return memcmp(&n, &pinf, sizeof n) == 0
66 || memcmp(&n, &ninf, sizeof n) == 0;
68 #endif
69 #endif