php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #60346 NAN != NAN
Submitted: 2011-11-21 10:15 UTC Modified: 2011-12-03 19:25 UTC
From: yunosh@php.net Assigned: frozenfire (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.4.0RC1 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: yunosh@php.net
New email:
PHP Version: OS:

 

 [2011-11-21 10:15 UTC] yunosh@php.net
Description:
------------
This is a regression from PHP 5.3.

Test script:
---------------
var_dump(NAN == NAN);

Expected result:
----------------
bool(true)

Actual result:
--------------
bool(false)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-21 11:16 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

"x = x returning false can be used to test if x is a quiet NaN"
see: http://en.wikipedia.org/wiki/NaN
 [2011-11-21 11:16 UTC] laruence@php.net
-Status: Open +Status: Bogus
 [2011-11-21 12:58 UTC] yunosh@php.net
It's not documented (http://www.php.net/manual/en/math.constants.php) and it's still a regression that isn't documented either: http://php.net/releases/NEWS_5_4_0_RC1.txt
 [2011-11-21 12:58 UTC] yunosh@php.net
-Status: Bogus +Status: Re-Opened
 [2011-11-21 13:02 UTC] laruence@php.net
what do you mean by regression ?
I have tested in PHP 5.2.14, the same output as PHP 5.4
 [2011-11-21 13:50 UTC] yunosh@php.net
You are right. I tracked a failing unit test with PHP 5.4.0RC down the wrong code path. The regression is in a different place.

In PHP 5.3
abs(NAN - NAN) <= 0
evaluates to true, in PHP 5.4 it evaluates to false.

And if you wonder where this strange code is coming from:
https://github.com/sebastianbergmann/phpunit/blob/3.5/PHPUnit/Framework/Constraint/IsEqual.php#L363
This seems to have been worked around in later PHPUnit versions though.
 [2011-11-21 14:32 UTC] laruence@php.net
I think NAN - NAN is undefined behavior, so you should not rely on such 
statements.

and I will mark this as a doc request, which request to explain the NAN's 
features. :)
 [2011-11-21 14:32 UTC] laruence@php.net
-Type: Bug +Type: Feature/Change Request -Package: Scripting Engine problem +Package: Documentation problem
 [2011-11-21 20:10 UTC] cataphract@php.net
-Status: Re-Opened +Status: Open -Type: Feature/Change Request +Type: Documentation Problem
 [2011-11-21 20:10 UTC] cataphract@php.net
Thank you for the report, but this has already been discussed and 5.4's behavior follows IEEE 754-2008.

See http://marc.info/?l=php-internals&m=130649054107748
 [2011-12-03 06:14 UTC] frozenfire@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: frozenfire
 [2011-12-03 06:14 UTC] frozenfire@php.net
My intention is to document NaN in the float type document, as a subsection. I'll 
make mention of the spec behaviour.
 [2011-12-03 19:25 UTC] frozenfire@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Master was down during commit, so the fix was revision 320310.
 [2011-12-03 19:25 UTC] frozenfire@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 16:01:34 2025 UTC