From: Marcus Boerger Date: Thu, 25 Mar 2004 22:36:36 +0000 (+0000) Subject: -Make NAN and INF more portable (atof() doesn't work on MSVC.6 for example) X-Git-Tag: php-5.0.0RC2RC1~225 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3450ed948f88285f604af7510434a33019735c02;p=php -Make NAN and INF more portable (atof() doesn't work on MSVC.6 for example) -Change test to use constants without prior conversion --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index c7cccee506..056cd0ab50 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -947,6 +947,35 @@ static void basic_globals_dtor(php_basic_globals *basic_globals_p TSRMLS_DC) } +#define PHP_DOUBLE_INFINITY_HIGH 0x7ff00000 +#define PHP_DOUBLE_QUIET_NAN_HIGH 0xfff80000 + +static double php_get_nan() +{ +#if defined(__i386__) || defined(_X86_) || defined(ALPHA) || defined(_ALPHA) || defined(__alpha) + double val; + ((php_uint32*)&val)[1] = PHP_DOUBLE_QUIET_NAN_HIGH; + ((php_uint32*)&val)[0] = 0; + return val; +#else + /* hope the target platform is ISO-C compliant */ + return atof("NAN"); +#endif +} + +static double php_get_inf() +{ +#if defined(__i386__) || defined(_X86_) || defined(ALPHA) || defined(_ALPHA) || defined(__alpha) + double val; + ((php_uint32*)&val)[1] = PHP_DOUBLE_QUIET_NAN_HIGH; + ((php_uint32*)&val)[0] = 0; + return val; +#else + /* hope the target platform is ISO-C compliant */ + return atof("INF"); +#endif +} + PHP_MINIT_FUNCTION(basic) { #ifdef ZTS @@ -982,8 +1011,8 @@ PHP_MINIT_FUNCTION(basic) REGISTER_MATH_CONSTANT(M_2_SQRTPI); REGISTER_MATH_CONSTANT(M_SQRT2); REGISTER_MATH_CONSTANT(M_SQRT1_2); - REGISTER_DOUBLE_CONSTANT("INF", atof("INF"), CONST_CS | CONST_PERSISTENT); - REGISTER_DOUBLE_CONSTANT("NAN", atof("NAN"), CONST_CS | CONST_PERSISTENT); + REGISTER_DOUBLE_CONSTANT("INF", php_get_inf(), CONST_CS | CONST_PERSISTENT); + REGISTER_DOUBLE_CONSTANT("NAN", php_get_nan(), CONST_CS | CONST_PERSISTENT); #if ENABLE_TEST_CLASS test_class_startup(); diff --git a/ext/standard/tests/math/bug27646.phpt b/ext/standard/tests/math/bug27646.phpt index 8c05bb9194..064fc0a0fa 100755 --- a/ext/standard/tests/math/bug27646.phpt +++ b/ext/standard/tests/math/bug27646.phpt @@ -3,17 +3,17 @@ Bug #27646 (Cannot serialize/unserialize non-finite numeric values) --FILE--