Bug #48418 [Ver->Csd]: NaN > NaN, NaN > 0, NaN < 0 return true
| From: | cmb@php.net | Date: | Sun, 14 Jun 2015 23:01:50 +0000 |
| Subject: | Bug #48418 [Ver->Csd]: NaN > NaN, NaN > 0, NaN < 0 return true | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193493@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=48418&edit=1
ID: 48418
Updated by: cmb@php.net
Reported by: phplists at stanvassilev dot com
Summary: NaN > NaN, NaN > 0, NaN < 0 return true
-Status: Verified
+Status: Closed
Type: Bug
Package: Math related
Operating System: *
PHP Version: 5.*, 6 (2009-08-04)
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
This bug has been fixed as of PHP 5.4.0, see
<http://3v4l.org/2KCXi>.
Previous Comments:
------------------------------------------------------------------------
[2010-01-10 11:49:51] for-bugs at hnw dot jp
Sorry, previous post was incollect. chrisstocktonaz's patch fixes my first comparison. I think
following patch is better.
--- php-5.3.1-orig/Zend/zend_operators.c 2010-01-10 20:41:36.000000000 +0900
+++ php-5.3.1/Zend/zend_operators.c 2010-01-10 20:44:58.000000000 +0900
@@ -1360,16 +1360,19 @@
case TYPE_PAIR(IS_DOUBLE, IS_LONG):
Z_DVAL_P(result) = Z_DVAL_P(op1) - (double)Z_LVAL_P(op2);
+ if (zend_isnan(Z_DVAL_P(result))) { Z_DVAL_P(result) = 1; }
ZVAL_LONG(result, 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);
+ if (zend_isnan(Z_DVAL_P(result))) { Z_DVAL_P(result) = 1; }
ZVAL_LONG(result, 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);
+ if (zend_isnan(Z_DVAL_P(result))) { Z_DVAL_P(result) = 1; }
ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
return SUCCESS;
------------------------------------------------------------------------
[2010-01-10 08:19:55] for-bugs at hnw dot jp
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.
------------------------------------------------------------------------
[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] kalle@php.net
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.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=48418
--
Edit this bug report at https://bugs.php.net/bug.php?id=48418&edit=1