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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at maisqi dot com
New email:
PHP Version: OS:

 

 [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: Fri Mar 05 04:01:23 2021 UTC