diff options
author | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-16 18:49:26 +0900 |
---|---|---|
committer | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-30 00:39:06 +0900 |
commit | fcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch) | |
tree | 64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/missing/isinf.c |
Fresh start
Diffstat (limited to 'jni/ruby/missing/isinf.c')
-rw-r--r-- | jni/ruby/missing/isinf.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/jni/ruby/missing/isinf.c b/jni/ruby/missing/isinf.c new file mode 100644 index 0000000..55187ad --- /dev/null +++ b/jni/ruby/missing/isinf.c @@ -0,0 +1,69 @@ +/* public domain rewrite of isinf(3) */ + +#ifdef __osf__ + +#define _IEEE 1 +#include <nan.h> + +int +isinf(double n) +{ + if (IsNANorINF(n) && IsINF(n)) { + return 1; + } + else { + return 0; + } +} + +#else + +#include "ruby/config.h" + +#if defined(HAVE_FINITE) && defined(HAVE_ISNAN) + +#include <math.h> +#ifdef HAVE_IEEEFP_H +#include <ieeefp.h> +#endif + +/* + * isinf may be provided only as a macro. + * ex. HP-UX, Solaris 10 + * http://www.gnu.org/software/automake/manual/autoconf/Function-Portability.html + */ +#ifndef isinf +int +isinf(double n) +{ + return (!finite(n) && !isnan(n)); +} +#endif + +#else + +#ifdef HAVE_STRING_H +# include <string.h> +#else +# include <strings.h> +#endif + +static double zero(void) { return 0.0; } +static double one (void) { return 1.0; } +static double inf (void) { return one() / zero(); } + +int +isinf(double n) +{ + static double pinf = 0.0; + static double ninf = 0.0; + + if (pinf == 0.0) { + pinf = inf(); + ninf = -pinf; + } + return memcmp(&n, &pinf, sizeof n) == 0 + || memcmp(&n, &ninf, sizeof n) == 0; +} +#endif +#endif |