2001-03-06 11:17:54 +03:00
|
|
|
/* public domain rewrite of isinf(3) */
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
#ifdef __osf__
|
|
|
|
|
|
|
|
#define _IEEE 1
|
|
|
|
#include <nan.h>
|
|
|
|
|
|
|
|
int
|
2006-01-05 08:29:48 +03:00
|
|
|
isinf(double n)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2003-12-20 18:45:15 +03:00
|
|
|
if (IsNANorINF(n) && IsINF(n)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2007-06-10 13:30:55 +04:00
|
|
|
#include "ruby/config.h"
|
2003-12-20 18:45:15 +03:00
|
|
|
|
|
|
|
#if defined(HAVE_FINITE) && defined(HAVE_ISNAN)
|
|
|
|
|
2005-10-13 18:30:54 +04:00
|
|
|
#include <math.h>
|
2003-12-20 18:45:15 +03:00
|
|
|
#ifdef HAVE_IEEEFP_H
|
|
|
|
#include <ieeefp.h>
|
|
|
|
#endif
|
|
|
|
|
2011-05-15 15:55:52 +04:00
|
|
|
/*
|
2007-11-13 19:54:27 +03:00
|
|
|
* 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
|
2003-12-20 18:45:15 +03:00
|
|
|
int
|
2006-01-05 08:29:48 +03:00
|
|
|
isinf(double n)
|
2003-12-20 18:45:15 +03:00
|
|
|
{
|
2003-12-21 13:30:24 +03:00
|
|
|
return (!finite(n) && !isnan(n));
|
2003-12-20 18:45:15 +03:00
|
|
|
}
|
2007-11-13 19:54:27 +03:00
|
|
|
#endif
|
2003-12-20 18:45:15 +03:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#else
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2006-01-05 08:29:48 +03:00
|
|
|
static double zero(void) { return 0.0; }
|
|
|
|
static double one (void) { return 1.0; }
|
|
|
|
static double inf (void) { return one() / zero(); }
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
int
|
2006-01-05 08:29:48 +03:00
|
|
|
isinf(double n)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
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
|
2003-12-20 18:45:15 +03:00
|
|
|
#endif
|