]> granicus.if.org Git - php/commitdiff
-Make NAN and INF more portable (atof() doesn't work on MSVC.6 for example)
authorMarcus Boerger <helly@php.net>
Thu, 25 Mar 2004 22:36:36 +0000 (22:36 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 25 Mar 2004 22:36:36 +0000 (22:36 +0000)
-Change test to use constants without prior conversion

ext/standard/basic_functions.c
ext/standard/tests/math/bug27646.phpt

index c7cccee50654d77643180777904fa6f19dcc865a..056cd0ab50245899fb122a2840cb3af205591fb2 100644 (file)
@@ -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();
index 8c05bb9194af05bb57abe3f2a43f04ec70100dcd..064fc0a0fab3711f5a7088f801502415e6a65048 100755 (executable)
@@ -3,17 +3,17 @@ Bug #27646 (Cannot serialize/unserialize non-finite numeric values)
 --FILE--
 <?php
 
-$f=-(float)INF;
+$f=-INF;
 var_dump($f);
 var_dump(serialize($f));
 var_dump(unserialize(serialize($f)));
 
-$f=(float)INF;
+$f=INF;
 var_dump($f);
 var_dump(serialize($f));
 var_dump(unserialize(serialize($f)));
 
-$f=(float)NAN;
+$f=NAN;
 var_dump($f);
 var_dump(serialize($f));
 var_dump(unserialize(serialize($f)));