php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54842 ceil yields a negative zero
Submitted: 2011-05-18 17:24 UTC Modified: 2011-05-18 19:39 UTC
From: php at maisqi dot com Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 5.3.6 OS: Windows XP32
Private report: No CVE-ID: None
View Add Comment Developer Edit
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:
17 + 22 = ?
Subscribe to this entry?

 
 [2011-05-18 17:24 UTC] php at maisqi dot com
Description:
------------
When doing some math with dates and "ceiling" the result, I got a negative zero!
I don't understand how that can be, so I presume it's an error.

Test script:
---------------
<?php

$dt = mktime (0, 0, 0, 5, 18, 2011);
$base = mktime (16, 16, 0, 5, 18, 2011);

echo 'dt: ', date ('Y-m-d', $dt), '<br />';
echo 'base: ', date ('Y-m-d', $base), '<br />';

echo '<br />';
echo 'dt - base: <strong>', ceil (($dt - $base) / 86400), '</strong>';

?>
<br /><br />
It outputs "-0" on PHP 5.3.6, under Windows XP 32 bits

Expected result:
----------------
The bolded text should be "0" (zero)

Actual result:
--------------
The bolded text is "-0" (negative zero)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-18 19:39 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2011-05-18 19:39 UTC] rasmus@php.net
This is not a bug. All floating point operations is done using IEEE-754 and both 
positive and negative 0 exists. You can read more about it here.

http://en.wikipedia.org/wiki/Signed_zero

You can add 0 to your result to make it never show -0 if you like.

eg. 0+ceil(...)
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Mar 07 02:01:25 2021 UTC