note 119128 rejected from migration70.incompatible by cmb
| From: | cmb@php.net | Date: | Fri, 22 Jul 2016 18:05:39 +0000 |
| Subject: | note 119128 rejected from migration70.incompatible by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206075@lists.php.net to get a copy of this message | ||
Note Submitter: anatoliy at ukhvanovy dot name
----
x = int(3) , y = float(0) , x / y = float(INF)
x = int(3) , y = int(0) , x / y = float(INF)
x = int(3) , y = float(-0) , x / y = float(-INF)
x = int(-3) , y = float(0) , x / y = float(-INF)
x = int(-3) , y = int(0) , x / y = float(-INF)
x = int(-3) , y = float(-0) , x / y = float(INF)
As we can see, PHP treats int(0) exactly as float(+0.0)Â â this is incorrect, IMO. I think,
PHP shouldn't treat it neither like float(+0.0) nor like float(-0.0)Â â because PHP
doesn't know what exactly is it. That's why, IMO, PHP shouldn't return ±INF, but
NAN when attempted to divide 3/int(0)Â â because PHP doesn't know is it 3/float(+0.0) or
3/float(-0.0) (which evaluates to +INF and -INF respectively â it's a huge
difference).
Here is the code, that produced output provided above:
<?php
error_reporting(0);
function dbg($x, $y) {
$d = $x / $y;
echo 'x = ';
var_dump($x);
echo ', y = ';
var_dump($y);
echo ', x / y = ';
var_dump ($d);
echo '<br />';
}
dbg(+3, +0.0);
dbg(+3, 0);
dbg(+3, -0.0);
dbg(-3, +0.0);
dbg(-3, 0);
dbg(-3, -0.0);
?>