Ruby
2.0.0p247(2013-06-27revision41674)
|
00001 /* public domain rewrite of isinf(3) */ 00002 00003 #ifdef __osf__ 00004 00005 #define _IEEE 1 00006 #include <nan.h> 00007 00008 int 00009 isinf(double n) 00010 { 00011 if (IsNANorINF(n) && IsINF(n)) { 00012 return 1; 00013 } 00014 else { 00015 return 0; 00016 } 00017 } 00018 00019 #else 00020 00021 #include "ruby/config.h" 00022 00023 #if defined(HAVE_FINITE) && defined(HAVE_ISNAN) 00024 00025 #include <math.h> 00026 #ifdef HAVE_IEEEFP_H 00027 #include <ieeefp.h> 00028 #endif 00029 00030 /* 00031 * isinf may be provided only as a macro. 00032 * ex. HP-UX, Solaris 10 00033 * http://www.gnu.org/software/automake/manual/autoconf/Function-Portability.html 00034 */ 00035 #ifndef isinf 00036 int 00037 isinf(double n) 00038 { 00039 return (!finite(n) && !isnan(n)); 00040 } 00041 #endif 00042 00043 #else 00044 00045 #ifdef HAVE_STRING_H 00046 # include <string.h> 00047 #else 00048 # include <strings.h> 00049 #endif 00050 00051 static double zero(void) { return 0.0; } 00052 static double one (void) { return 1.0; } 00053 static double inf (void) { return one() / zero(); } 00054 00055 int 00056 isinf(double n) 00057 { 00058 static double pinf = 0.0; 00059 static double ninf = 0.0; 00060 00061 if (pinf == 0.0) { 00062 pinf = inf(); 00063 ninf = -pinf; 00064 } 00065 return memcmp(&n, &pinf, sizeof n) == 0 00066 || memcmp(&n, &ninf, sizeof n) == 0; 00067 } 00068 #endif 00069 #endif 00070