|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-06-04 21:31 UTC] nikic@php.net
Description:
------------
We perform (long|double)->double narrowing even if chains of operations that only eventually result in a double are involved. This can lead to wrong results because parts of the calculation that would have been performed on integers are performed on doubles instead, with the corresponding loss in precision.
We need to either not narrow for such chains or ensure that the transformation is safe.
Test script:
---------------
<?php
function test() {
$b = false;
$x = (1<<53)+1;
do {
$x = 1.0 * ($x - (1<<53));
} while ($b);
return $x;
}
var_dump(test());
Expected result:
----------------
float(1)
Actual result:
--------------
float(0)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Sun Mar 29 12:00:01 2026 UTC |
Added negative case: <?php function test() { $b = false; $x = -(1<<53) -1; do { $x = 1.0 * ($x + (1<<53)); } while ($b); return $x; } var_dump(test());