ID: 48418
Comment by: for-bugs at hnw dot jp
Reported By: phplists at stanvassilev dot com
Status: Verified
Bug Type: Math related
Operating System: *
PHP Version: 5.*, 6 (2009-08-04)
New Comment:
This is good fix. The fix affects only following comparisons:
* NaN < [any number]
* Inf < Inf
* -Inf < -Inf
They are all ture on my machine, but all should be false.
Previous Comments:
------------------------------------------------------------------------
[2009-10-13 05:14:41] chrisstocktonaz at gmail dot com
Sorry for the extra noise, took a harder look and here is the real
fix.
Index: Zend/zend_operators.c
===================================================================
--- Zend/zend_operators.c (revision 289604)
+++ Zend/zend_operators.c (working copy)
@@ -1360,17 +1360,17 @@
case TYPE_PAIR(IS_DOUBLE, IS_LONG):
Z_DVAL_P(result) = Z_DVAL_P(op1) -
(double)Z_LVAL_P(op2);
- ZVAL_LONG(result,
ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
+ ZVAL_LONG(result, zend_isnan(Z_DVAL_P(op1)) ? 1
:
ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
return SUCCESS;
case TYPE_PAIR(IS_LONG, IS_DOUBLE):
Z_DVAL_P(result) = (double)Z_LVAL_P(op1) -
Z_DVAL_P(op2);
- ZVAL_LONG(result,
ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
+ ZVAL_LONG(result, zend_isnan(Z_DVAL_P(op2)) ? 1
:
ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
return SUCCESS;
case TYPE_PAIR(IS_DOUBLE, IS_DOUBLE):
Z_DVAL_P(result) = Z_DVAL_P(op1) -
Z_DVAL_P(op2);
- ZVAL_LONG(result,
ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
+ ZVAL_LONG(result, (zend_isnan(Z_DVAL_P(op1)) ||
zend_isnan(Z_DVAL_P(op2))) ? 1 :
ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
return SUCCESS;
case TYPE_PAIR(IS_ARRAY, IS_ARRAY):
------------------------------------------------------------------------
[2009-05-30 19:48:30] [email protected]
C:\php\src>php -v
PHP 5.3.0RC3-dev (cli) (built: May 29 2009 09:57:23)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
C:\php\src>php -r "$nan = sqrt(-1); var_dump($nan, $nan > $nan, $nan <
0, $nan > 0);"
float(NAN)
bool(true)
bool(true)
bool(true)
Same on Windows
------------------------------------------------------------------------
[2009-05-28 19:05:20] phplists at stanvassilev dot com
And to add a note:
$NaN >= $NaN
$NaN >= 0
$NaN <= 0
These also return true and must return false.
------------------------------------------------------------------------
[2009-05-28 18:57:57] phplists at stanvassilev dot com
Description:
------------
Tested on Gentoo, CentOS, OSX.
This is possibly NOT related to the Windows NaN bug, as Windows is NOT
affected by this issue.
However, please test if any fix doesn't cause regression on Windows.
NaN > NaN, NaN > 0, NaN < 0 return true, while they should return false
in all cases (any comparison where either side is NaN, should return
false).
Reproduce code:
---------------
$NaN = sqrt(-1);
var_dump($NaN > $NaN);
var_dump($NaN > 0);
var_dump($NaN < 0);
Expected result:
----------------
float(NAN)
bool(false)
bool(false)
bool(false)
Actual result:
--------------
float(NAN)
bool(true)
bool(true)
bool(true)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48418&edit=1