php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41338 ceil() gives strange results
Submitted: 2007-05-09 09:10 UTC Modified: 2007-05-09 09:19 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: kjarli at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.2 OS: Windows vista
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
32 + 10 = ?
Subscribe to this entry?

 
 [2007-05-09 09:10 UTC] kjarli at gmail dot com
Description:
------------
when creating formulas, i encountered a strange bug:
this is the basic forumula:
ceil(user_hp * 1.1)

when user_hp = 100 you get the following formula

ceil(100*(110/100)) in my script.

this will result 111 instead of 110


Reproduce code:
---------------
<?php
$lol1 = ceil(100 * (110 / 100));
$lol2 = ceil(100 * 1.1);
$lol3 = ceil(110);
$lol4 = ceil(110.0);

echo $lol1;
?> 
<br />
<?php
echo $lol2;
?> 
<br />
<?php
echo $lol3;
?> 
<br />
<?php
echo $lol4;
?>

Expected result:
----------------
110
110
110
110


Actual result:
--------------
111
111
110
110

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-09 09:19 UTC] tony2001@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 Nov 09 21:01:28 2024 UTC