Doc #77778 [Com]: 0.0 is falsy but docs do not say -0.0 is falsy too
| From: | lewisje at alumni dot iu dot edu | Date: | Thu, 21 Mar 2019 18:42:02 +0000 |
| Subject: | Doc #77778 [Com]: 0.0 is falsy but docs do not say -0.0 is falsy too | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-16498@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77778&edit=1
ID: 77778
Comment by: lewisje at alumni dot iu dot edu
Reported by: lewisje at alumni dot iu dot edu
Summary: 0.0 is falsy but docs do not say -0.0 is falsy too
Status: Open
Type: Documentation Problem
Package: *General Issues
Operating System: CentOS 6
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
As I showed above, even though -0.0 and 0.0 show as equal under strict equality, they are distinct
values, because 1/-0.0 and 1/0.0 are the respective distinct values -INF and INF; this is by design,
to quote from Section 5.7 of ANSI/IEEE Std 754-1985: http://www.validlab.com/754R/web-2008/standards/754.pdf
> Comparisons shall ignore the sign of zero (so +0 = â0).
Sections 7.2 and 6.3 together imply that it is by design that 1/0.0 is INF and 1/-0.0 is -INF.
---
It does seem like a nitpick, but it just stuck out to me after I had noticed a similar distinction
in Ecmascript (Crockford and many other expositors don't make a distinction, while the
Definitive Guide by Flanagan did make it); also, the way I mentioned earlier to be able to
distinguish the positive and negative zero floats is exactly what is done in the polyfill for
Object.is from ES6. (I'm not saying here that it's vital for PHP to have some built-in
function that distinguishes -0.0 from 0.0 and compares NAN as equal to itself, the way Object.is
does.)
Previous Comments:
------------------------------------------------------------------------
[2019-03-21 18:14:05] requinix@php.net
If 0.0 and -0.0 are strictly identical then under what logic should (bool)0.0 be false and
(bool)-0.0 be true?
Seems silly to me that the docs should have to point out that both 0.0 and -0.0 are false, but I
suppose it's an easy enough edit that it's not worth arguing about.
------------------------------------------------------------------------
[2019-03-21 16:55:31] lewisje at alumni dot iu dot edu
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 this bug report at https://bugs.php.net/bug.php?id=77778&edit=1