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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 18:01:30 2024 UTC