php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43267 Error in Floating Point Operation
Submitted: 2007-11-12 18:30 UTC Modified: 2007-11-12 18:59 UTC
From: armadillo at penguinfriends dot org Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.5 OS: CentOS
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: armadillo at penguinfriends dot org
New email:
PHP Version: OS:

 

 [2007-11-12 18:30 UTC] armadillo at penguinfriends dot org
Description:
------------
The is a bug in many php versions with a floating point operation. Tested PHP-Versions: 4.4.1 (Debian Sarge (3.1)), 5.0.4 (OpenSuse 10.0 x86_64), 5.2.5 (CentOS 5). It is a conversion from float to int, which doesn't work correct. See the reprocedure code and the expected result for more.

When running it on the ssh-console on CentOS 5, on the native login console, the following output will be generated:

setitimer: php (pid = 2731) provided invalid timeval it_value: sec = -1 tv_usec = 0

Hope this will help! ;)

Reproduce code:
---------------
<?php echo (int)(100*2.55); ?>

Expected result:
----------------
255

Actual result:
--------------
254

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-12 18:59 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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC