From 5820be029ae4c9494d21766ef923b661cb06a7ef Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 6 Apr 2015 22:03:44 +0300 Subject: [PATCH] 0.0 / 0.0 = NaN --- Zend/zend_operators.c | 24 +------------------ tests/lang/operators/divide_variationStr.phpt | 18 +++++++------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 59b8abf7ab3..c5ef35331f6 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 08250db28f1..f54013fcece 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===