php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65852 Wrong documentation about NAN comparison
Submitted: 2013-10-07 17:46 UTC Modified: 2017-01-28 16:33 UTC
From: chalkerx at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.5.4 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: chalkerx at gmail dot com
New email:
PHP Version: OS:

 

 [2013-10-07 17:46 UTC] chalkerx at gmail dot com
Description:
------------
http://www.php.net/manual/en/types.comparisons.php states:
> Some numeric operations can result in a value represented by the constant NAN. Any loose or strict comparisons of this value against any other value, including itself, will have a result of FALSE

But that is invalid, because NAN loosely equals to boolean true.

Test script:
---------------
var_dump(sqrt(-1));
var_dump(sqrt(-1) == true);

Expected result:
----------------
As per documentation, the result should be:

double(NAN)
bool(false)

The documentation should be consistent with what actually happens.

Actual result:
--------------
double(NAN)
bool(true)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-07 17:48 UTC] chalkerx at gmail dot com
-Summary: Fileinfo file() method and any mp3 file crashes php. +Summary: Wrong documentation about NAN comparison.
 [2013-10-07 17:48 UTC] chalkerx at gmail dot com
Whoops, browser-saved title from the old bug.
 [2013-10-09 09:23 UTC] phpmpan at mpan dot pl
As documentation states, conversion from NaN to boolean should yield TRUE, and hence TRUE == TRUE will be TRUE too.

I believe the wording is just not precise and "value" means "numeric value" in this case. Of course this needs to be fixed.
 [2017-01-28 16:29 UTC] cmb@php.net
-Summary: Wrong documentation about NAN comparison. +Summary: Wrong documentation about NAN comparison -Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2017-01-28 16:29 UTC] cmb@php.net
> I believe the wording is just not precise and "value" means
> "numeric value" in this case.

Even comparing non-numeric strings with NAN yields FALSE[1]. The
sole exception appears to be TRUE[2].

[1] <https://3v4l.org/orCLn>
[2] <https://3v4l.org/VY7oe>
 [2017-01-28 16:32 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=341793
Log: Fix #65852: Wrong documentation about NAN comparison
 [2017-01-28 16:33 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2017-01-28 16:33 UTC] cmb@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.
 [2020-02-07 06:06 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=0ade9d91c1e45a8afef45c9ee514fccdc1900ca1
Log: Fix #65852: Wrong documentation about NAN comparison
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 21:00:02 2026 UTC