php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65420 Comparison with double values wrong
Submitted: 2013-08-08 08:52 UTC Modified: 2013-08-08 10:44 UTC
From: g dot karagyozov at gmail dot com Assigned:
Status: Not a bug Package: Apache related
PHP Version: 5.5.1 OS: OSX
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: g dot karagyozov at gmail dot com
New email:
PHP Version: OS:

 

 [2013-08-08 08:52 UTC] g dot karagyozov at gmail dot com
Description:
------------
Comparison with some double values is not correct.

Test script:
---------------
var_dump(1.8 > (1.9 - 0.1));
var_dump(1.1 > (1.2 - 0.1));

Expected result:
----------------
false expected

Actual result:
--------------
true returned

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-08 10:44 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2013-08-08 10:44 UTC] rasmus@php.net
Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/

Thank you for your interest in PHP.

.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 20:01:31 2025 UTC