The manual is not clear on the comparison of floating-point numbers;
$a = 1.11;
$b = 1.11;
if ($a = = $b) {
The result is true;
}
Not to say never compare two floating-point numbers for equality?
What is the meaning of this, the calculation of the floating point number can not be compared?
------to solve the idea----------------------
Not to say not to compare, but to say that because of the accuracy of the reason, seemingly the same two numbers, compared not equal
You compare two of the same precision number, of course there is no problem
------to solve the idea----------------------
Not to compare, just not accurate.
For example:
$a = 1.1000000000000000001;
$b = 1.1000000000000000011;
if ($a = = $b) {
echo ' equal ';
}else{
echo ' Not equal ';
}
Output equal
------to solve the idea----------------------
$a = 1.00000000000000001;
$b = 1.00000000000000002;
Var_dump ($a = = $b); BOOL (true) is actually equal
$s = pack (' F ', $a);
for ($i =0; $i
Echo Php_eol;
$s = pack (' F ', $b);
for ($i =0; $i
Echo Php_eol;
It turns out they're the same when they save it on a computer.
00000000 00000000 10000000 00111111
00000000 00000000 10000000 00111111