|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16551 ceil results -0
Submitted: 2002-04-11 09:38 UTC Modified: 2002-04-24 12:19 UTC
From: alberty at neptunelabs dot de Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.0CVS-2002-04-11 OS: i686-pc-linux-gnu
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.
Block user comment
Status: Assign to:
Bug Type:
From: alberty at neptunelabs dot de
New email:
PHP Version: OS:


 [2002-04-11 09:38 UTC] alberty at neptunelabs dot de

the follow code results -0,

echo $a;

maybe, this is a convertion problem with float types.

also, why the ceil() command results a floating point number and not an integer?
It makes sense when the ceil command accept a precision like round()...




Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-24 08:24 UTC] alberty at neptunelabs dot de
The problem is also affected on round().

echo round($a);
// results: -0


 [2002-04-24 08:27 UTC]
This is expected behavior. ceil() and floor() return a float because of the large range of supported numbers.

 [2002-04-24 08:34 UTC] alberty at neptunelabs dot de

It is true that ceil() and round() return floating point numbers, but -0 is not a number.
 [2002-04-24 09:26 UTC] alberty at neptunelabs dot de
Hi derick,

here is the proof of my statement.

try this code:

echo "<tt>(machine code representation)<br><br>";

// correct result
echo " $b1 = ";
for ($l=0,$o1='';$l<strlen($p);$l++){
echo $o1.'h';
echo '<hr size=1>';

//wrong result
echo "$b2 = ";
for ($l=0,$o2='';$l<strlen($p);$l++){
echo $o2.'h';

echo "<hr>the question is, is $b1 == $b2<br>";
echo "php mean:<br><font color=#000088>";
if ($b1==$b2) echo "yes, this is true.<br>";
else echo "no, this is false.<br>";
echo "</font>but $o1 != $o2<br>";
echo "and also $o2 != 0";

echo "</tt>";

The big problem with this behavior is, if you using round() or ceil() to output results
of mathematical function, you can't be sure if the result what you expected or not.

This can have fatal consequences for programs they output e.g. statitics in text files and
other programs interpret the php results wrong!

This is not a trivial problem!
 [2002-04-24 12:19 UTC]
The php functions just wrap calls to the underlining C library. On Linux glibc happens to return -0 on ceil. Very little we can do here.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Mar 03 19:01:28 2024 UTC