com php-src: 0.0 / 0.0 = NaN: Zend/zend_operators.c tests/lang/operators/divide_variationStr.phpt
| From: | Dmitry Stogov | Date: | Mon, 06 Apr 2015 19:03:44 +0000 |
| Subject: | com php-src: 0.0 / 0.0 = NaN: Zend/zend_operators.c tests/lang/operators/divide_variationStr.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-86106@lists.php.net to get a copy of this message | ||
Commit: 5820be029ae4c9494d21766ef923b661cb06a7ef
Author: Dmitry Stogov <dmitry@zend.com> Mon, 6 Apr 2015 22:03:44 +0300
Parents: 9a573790245e192e826a42cd14c51709759c6bc0
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5820be029ae4c9494d21766ef923b661cb06a7ef
Log:
0.0 / 0.0 = NaN
Changed paths:
M Zend/zend_operators.c
M tests/lang/operators/divide_variationStr.phpt
Diff:
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index 59b8abf..c5ef353 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -1064,22 +1064,6 @@ ZEND_API int ZEND_FASTCALL pow_function(zval *result, zval *op1, zval *op2)
/* {
}
/* }}} */
-static zend_always_inline void make_inf(zval *result, int neg) /* {{{ */
-{
-#if HAVE_HUGE_VAL_INF
- ZVAL_DOUBLE(result, neg ? -HUGE_VAL : HUGE_VAL);
-#elif defined(__i386__) || defined(_X86_) || defined(ALPHA) || defined(_ALPHA) || defined(__alpha)
- result->value.ww.w1 = neg ? 0xfff00000 : 0x7ff00000;
- result->value.ww.w2 = 0;
- Z_TYPE_INFO_P(result) = IS_DOUBLE;
-#elif HAVE_ATOF_ACCEPTS_INF
- ZVAL_DOUBLE(neg ? aatof("-INF") : tof("INF"));
-#else
- ZVAL_DOUBLE(result, neg ? (-1.0/0.0) : (1.0/0.0));
-#endif
-}
-/* }}} */
-
ZEND_API int ZEND_FASTCALL div_function(zval *result, zval *op1, zval *op2) /* {{{ */
{
zval op1_copy, op2_copy;
@@ -1090,7 +1074,7 @@ ZEND_API int ZEND_FASTCALL div_function(zval *result, zval *op1, zval *op2) /*
{
case TYPE_PAIR(IS_LONG, IS_LONG):
if (Z_LVAL_P(op2) == 0) {
zend_error(E_WARNING, "Division by zero");
- make_inf(result, Z_LVAL_P(op1) < 0);
+ ZVAL_DOUBLE(result, ((double) Z_LVAL_P(op1) / (double) Z_LVAL_P(op2)));
return SUCCESS;
} else if (Z_LVAL_P(op2) == -1 && Z_LVAL_P(op1) == ZEND_LONG_MIN) {
/* Prevent overflow error/crash */
@@ -1107,8 +1091,6 @@ ZEND_API int ZEND_FASTCALL div_function(zval *result, zval *op1, zval *op2) /*
{
case TYPE_PAIR(IS_DOUBLE, IS_LONG):
if (Z_LVAL_P(op2) == 0) {
zend_error(E_WARNING, "Division by zero");
- make_inf(result, Z_DVAL_P(op1) < 0.0);
- return SUCCESS;
}
ZVAL_DOUBLE(result, Z_DVAL_P(op1) / (double)Z_LVAL_P(op2));
return SUCCESS;
@@ -1116,8 +1098,6 @@ ZEND_API int ZEND_FASTCALL div_function(zval *result, zval *op1, zval *op2) /*
{
case TYPE_PAIR(IS_LONG, IS_DOUBLE):
if (Z_DVAL_P(op2) == 0) {
zend_error(E_WARNING, "Division by zero");
- make_inf(result, Z_LVAL_P(op1) < 0);
- return SUCCESS;
}
ZVAL_DOUBLE(result, (double)Z_LVAL_P(op1) / Z_DVAL_P(op2));
return SUCCESS;
@@ -1125,8 +1105,6 @@ ZEND_API int ZEND_FASTCALL div_function(zval *result, zval *op1, zval *op2) /*
{
case TYPE_PAIR(IS_DOUBLE, IS_DOUBLE):
if (Z_DVAL_P(op2) == 0) {
zend_error(E_WARNING, "Division by zero");
- make_inf(result, Z_LVAL_P(op1) < 0.0);
- return SUCCESS;
}
ZVAL_DOUBLE(result, Z_DVAL_P(op1) / Z_DVAL_P(op2));
return SUCCESS;
diff --git a/tests/lang/operators/divide_variationStr.phpt
b/tests/lang/operators/divide_variationStr.phpt
index 08250db..f54013f 100644
--- a/tests/lang/operators/divide_variationStr.phpt
+++ b/tests/lang/operators/divide_variationStr.phpt
@@ -22,7 +22,7 @@ foreach ($strVals as $strVal) {
===DONE===
--EXPECT--
--- testing: '0' / '0' ---
-float(INF)
+float(NAN)
--- testing: '0' / '65' ---
int(0)
--- testing: '0' / '-44' ---
@@ -32,7 +32,7 @@ float(0)
--- testing: '0' / '-7.7' ---
float(-0)
--- testing: '0' / 'abc' ---
-float(INF)
+float(NAN)
--- testing: '0' / '123abc' ---
int(0)
--- testing: '0' / '123e5' ---
@@ -48,7 +48,7 @@ int(0)
--- testing: '0' / '3.4a' ---
float(0)
--- testing: '0' / 'a5.9' ---
-float(INF)
+float(NAN)
--- testing: '65' / '0' ---
float(INF)
--- testing: '65' / '65' ---
@@ -162,7 +162,7 @@ float(-2.2647058823529)
--- testing: '-7.7' / 'a5.9' ---
float(-INF)
--- testing: 'abc' / '0' ---
-float(INF)
+float(NAN)
--- testing: 'abc' / '65' ---
int(0)
--- testing: 'abc' / '-44' ---
@@ -172,7 +172,7 @@ float(0)
--- testing: 'abc' / '-7.7' ---
float(-0)
--- testing: 'abc' / 'abc' ---
-float(INF)
+float(NAN)
--- testing: 'abc' / '123abc' ---
int(0)
--- testing: 'abc' / '123e5' ---
@@ -188,7 +188,7 @@ int(0)
--- testing: 'abc' / '3.4a' ---
float(0)
--- testing: 'abc' / 'a5.9' ---
-float(INF)
+float(NAN)
--- testing: '123abc' / '0' ---
float(INF)
--- testing: '123abc' / '65' ---
@@ -386,7 +386,7 @@ float(1)
--- testing: '3.4a' / 'a5.9' ---
float(INF)
--- testing: 'a5.9' / '0' ---
-float(INF)
+float(NAN)
--- testing: 'a5.9' / '65' ---
int(0)
--- testing: 'a5.9' / '-44' ---
@@ -396,7 +396,7 @@ float(0)
--- testing: 'a5.9' / '-7.7' ---
float(-0)
--- testing: 'a5.9' / 'abc' ---
-float(INF)
+float(NAN)
--- testing: 'a5.9' / '123abc' ---
int(0)
--- testing: 'a5.9' / '123e5' ---
@@ -412,5 +412,5 @@ int(0)
--- testing: 'a5.9' / '3.4a' ---
float(0)
--- testing: 'a5.9' / 'a5.9' ---
-float(INF)
+float(NAN)
===DONE===