Req #72239 [Nab]: float zero should be equal int 0 even with ===

From: Date: Thu, 19 May 2016 14:37:18 +0000
Subject: Req #72239 [Nab]: float zero should be equal int 0 even with ===
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201198@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72239&edit=1

 ID:                 72239
 User updated by:    dosergio at gmail dot com
 Reported by:        dosergio at gmail dot com
 Summary:            float zero should be equal int 0 even with ===
 Status:             Not a bug
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   all
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

I know that this idea will not be implemented.
This is more philosophy than computing:
Concepts of numbers, and specially, the definition of zero.
Anyway thanks


Previous Comments:
------------------------------------------------------------------------
[2016-05-19 14:23:43] dosergio at gmail dot com

OP1          OP2                    TYPE CHECK          RESULT
--------------------------------------------------------------
number      "not number"            On                  false
--------------------------------------------------------------
float       int    if(0.0 and 0 )   Off                 true
--------------------------------------------------------------
float       int    if(any != 0.0)   On                  false

------------------------------------------------------------------------
[2016-05-19 13:54:31] dosergio at gmail dot com

You asked why zero?
The answer is: because zero is a special value. Means nothing, in any types of numbers, int, float,
double, real, etc.
Envolving strings in the comparison was an exageration. What I proposed would apply only in NUMERIC
comparisons with both sides ZERO. because zero is absolute. A number only starts being float when it
is different from zero.
But ok
Lets write === 0.0 because 0 is not 0.0 so, I am talking about numbers and the intrinsic value.

------------------------------------------------------------------------
[2016-05-19 06:14:47] pajoye@php.net

Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/

Thank you for your interest in PHP.

Better explanation.

------------------------------------------------------------------------
[2016-05-19 02:55:14] requinix@php.net

Why stop at 0? How about making 1 === 1.0? And what about strings? 0 should === "0" too.
Of course since 0 === 0.0 then that means 0 === "0.0" too.

=== means identical. If you don't want an identical comparison then don't use it.

------------------------------------------------------------------------
[2016-05-19 02:45:45] dosergio at gmail dot com

Description:
------------
Zero is zero, I think there is no "float flavour" of zero and "int flavour" of
zero since zero is nothing.

Why to check data type when both sides are absolute ZERO ?

So for the comparison 0 === 0.0, I think PHP should go beyound the memory/way of storing the number,
and consider that we are comparing two absolute zero values, so the result could be TRUE as it is in
other languages.

The data type check only makes sense to enter in scene when one of the compared values differ from
zero!
 
What makes a factual float? One number like 0.0000000000001 ! I mean, different from zero.

The problem: 
A programmer knows that a value in some condition is zero.
But when comparing  if ($myValue === 0) causes failure, since PHP obliges you to write if ($myValue
=== 0.0) 


 



Test script:
---------------
$x = floatVal(0);

if( $x === 0){ // why to check data type when both sides are ZERO ?
  echo 'Will not enter here, php expects 0.0';
} else {
  echo '0 and 0.0 is the same "VALUE"';
}



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=72239&edit=1


Thread (6 messages)

« previous php.bugs (#201198) next »