php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27138 0.1 and 0.7 evaluate strangely
Submitted: 2004-02-03 21:48 UTC Modified: 2004-02-03 21:55 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: kennyt@php.net Assigned:
Status: Not a bug Package: Math related
PHP Version: 5CVS-2004-02-03 (dev) OS:
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: kennyt@php.net
New email:
PHP Version: OS:

 

 [2004-02-03 21:48 UTC] kennyt@php.net
Description:
------------
I saw this in a manual note. I don't know if it's 
really a problem, but others have agreed it's a bug, 
so...

Only when using the floats 0.1 and 0.7 and multiplying 
by a number large enough to bring the product of the 
two floats' sums above 1 does a strange evaluation 
become apparent.

Reproduce code:
---------------
echo (int)((0.1 + 0.7) * 10);
echo intval((0.1 + 0.7) * 10);
echo (int)((0.1 + 0.7) * 20);
echo (int)((0.1 + 0.8) * 20);
echo (int)((0.1 + 0.8) * 10);

Expected result:
----------------
8
8
16
18
9

Actual result:
--------------
7
7
15
18
9

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-03 21:53 UTC] edink@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.
 
Thank you for your interest in PHP.

.
 [2004-02-03 21:55 UTC] kennyt@php.net
Wow, just five minutes! We're really doing well today! 
:)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 07 00:01:28 2024 UTC