|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-08-05 02:39 UTC] for-bugs at hnw dot jp
Description: ------------ There is == operator's problem dealing with NaN(Not a Number) in PHP 5.3.0alpha1. This behavior is different with PHP 5.0.0-5.2.6, so this is compatibility problem. Reproduce code: --------------- <?php $nan = (-1e300*1e300)/(1e300*1e300); // float(NAN) var_dump($nan==''); var_dump($nan==0.5); var_dump($nan==50); var_dump($nan=='500'); var_dump($nan=='abc'); var_dump($nan==$nan); Expected result: ---------------- bool(false) bool(false) bool(false) bool(false) bool(false) bool(false) Actual result: -------------- bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 15:00:01 2025 UTC |
NaN is not exact number. So, NaN should not equals itself. Additionaly, NaN == NaN is false in C. You can see behavior of C as follows. $ cat nan.c int main() {double d;d=(-1e300*1e300)/(1e300*1e300);if (d==d) return 1; else return 2;} $ gcc nan.c; ./a.out; echo $? 2 $