Bug #72335 [Opn]: Misoptimize due to type narrowing

From: Date: Mon, 06 Jun 2016 06:02:06 +0000
Subject: Bug #72335 [Opn]: Misoptimize due to type narrowing
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201464@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72335&edit=1 ID: 72335 Updated by: laruence@php.net Reported by: nikic@php.net Summary: Misoptimize due to type narrowing Status: Open Type: Bug Package: opcache PHP Version: master-Git-2016-06-04 (Git) Block user comment: N Private report: N New Comment: something like: https://gist.github.com/laruence/f1d62308ff7dc9557f934b8c2e444646 Previous Comments: ------------------------------------------------------------------------ [2016-06-06 05:40:34] laruence@php.net we should check if there is any precision losing while converting long to double. ------------------------------------------------------------------------ [2016-06-04 21:31:47] 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) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72335&edit=1

« previous php.bugs (#201464) next »