Doc #77778 [NEW]: -0.0 and 0.0 are distinct values.
| From: | lewisje at alumni dot iu dot edu | Date: | Thu, 21 Mar 2019 16:55:31 +0000 |
| Subject: | Doc #77778 [NEW]: -0.0 and 0.0 are distinct values. | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-16496@lists.php.net to get a copy of this message | ||
From: lewisje at alumni dot iu dot edu
Operating system: CentOS 6
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:-0.0 and 0.0 are distinct values.
Description:
------------
---
From manual page: https://php.net/language.types.boolean
---
Among the values listed as falsy is "the float 0.0 (zero)", but the
float -0.0 is not listed; however, it is both falsy and distinct from
0.0: As ought to be pointed out in https://php.net/language.types.float,
IEEE-754 floating-point arithmetic includes distinct 0.0 and -0.0
values; even though they will be treated as equal under strict equality,
1/0.0 is INF, while 1/-0.0 is -INF, again as in the IEEE-754
specification.
Test script:
---------------
<?php
var_dump(1/0.0); // float(INF)
var_dump(1/-0.0); // float(-INF)
var_dump(-0.0 === 0.0); // bool(true)
var_dump((bool)-0.0); // bool(false)
?>
Expected result:
----------------
Based on the literal documentation, (bool)-0.0 ought to be true.
Actual result:
--------------
(bool)-0.0 is false, and as the other statements show, -0.0 can be
distinguished from 0.0, which means that it is another falsy value.
--
Edit bug report at https://bugs.php.net/bug.php?id=77778&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77778&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77778&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77778&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77778&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77778&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77778&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77778&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77778&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77778&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77778&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77778&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77778&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77778&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77778&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77778&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77778&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77778&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77778&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77778&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77778&r=mysqlcfg