helly Thu Mar 25 17:36:36 2004 EDT
Modified files:
/php-src/ext/standard basic_functions.c
/php-src/ext/standard/tests/math bug27646.phpt
Log:
-Make NAN and INF more portable (atof() doesn't work on MSVC.6 for example)
-Change test to use constants without prior conversion
http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.655&r2=1.656&ty=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.655
php-src/ext/standard/basic_functions.c:1.656
--- php-src/ext/standard/basic_functions.c:1.655 Tue Mar 23 17:30:25 2004
+++ php-src/ext/standard/basic_functions.c Thu Mar 25 17:36:36 2004
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.c,v 1.655 2004/03/23 22:30:25 helly Exp $ */
+/* $Id: basic_functions.c,v 1.656 2004/03/25 22:36:36 helly Exp $ */
#include "php.h"
#include "php_streams.h"
@@ -947,6 +947,35 @@
}
+#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 @@
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();
http://cvs.php.net/diff.php/php-src/ext/standard/tests/math/bug27646.phpt?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/standard/tests/math/bug27646.phpt
diff -u php-src/ext/standard/tests/math/bug27646.phpt:1.1
php-src/ext/standard/tests/math/bug27646.phpt:1.2
--- php-src/ext/standard/tests/math/bug27646.phpt:1.1 Tue Mar 23 17:30:25 2004
+++ php-src/ext/standard/tests/math/bug27646.phpt Thu Mar 25 17:36:36 2004
@@ -3,17 +3,17 @@
--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)));
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php