php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45278 round is not working consitently on 64bit
Submitted: 2008-06-16 10:20 UTC Modified: 2008-06-19 21:20 UTC
From: kelfe at gmx dot de Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.6 OS: Gentoo64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kelfe at gmx dot de
New email:
PHP Version: OS:

 

 [2008-06-16 10:20 UTC] kelfe at gmx dot de
Description:
------------
the demo code procduces the expected results on a gentoo 32 bit install (amd 2400+) dev-lang/php-5.2.6-r1
but fails with the actual results on a 64bit install (intel xeon) from the same ebuild

the error can reproduced on an older ubuntu PHP 5.2.3 running 64bit as well


the loop and sum was only added to reduce the code (could do 20 round of the calculated values as well for the same result)

Reproduce code:
---------------
php -r 'for($i=0;$i<20;$i++) echo round($i+0.015,2)."\n";'

Expected result:
----------------
0.02
1.02
2.02
3.02
4.02
5.02
6.02
7.02
8.02
9.02
10.02
11.02
12.02
13.02
14.02
15.02
16.02
17.02
18.02
19.02


Actual result:
--------------
0.02
1.01
2.02
3.02
4.01
5.01
6.02
7.02
8.02
9.02
10.02
11.02
12.02
13.02
14.02
15.02
16.02
17.02
18.02
19.02


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-19 21:20 UTC] johannes@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://docs.sun.com/source/806-3568/ncg_goldberg.html
 
Thank you for your interest in PHP.


 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Jul 04 00:05:44 2022 UTC