Bug #73358 [NEW]: Bug with float to int conversion

From: Date: Thu, 20 Oct 2016 15:49:05 +0000
Subject: Bug #73358 [NEW]: Bug with float to int conversion
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204936@lists.php.net to get a copy of this message
From:             x-alexander93 at yandex dot ru
Operating system: Debian 8.6, Windows 7
PHP version:      5.6.27
Package:          *General Issues
Bug Type:         Bug
Bug description:Bug with float to int conversion

Description:
------------
Hi!
I've found a bug with (possible?) float to int conversion. Well, I don't
know to which category it could be more closely related.
I found the same results on Debian 8.6, CentOS 7 (with the latest 5.6
version from remi repo) and on the old XAMPP install with PHP 5.5 under
Windows 7.
No PEAR or PECL packets were installed. Everything from standard PHP
library (like imagick etc).
Here is the result of test script execution:
http://pastebin.com/JWJby27F

Test script:
---------------
<?php
// from 246
$from = "8.2" * "30";
// to 342
$to = "11.4" * "30";
$a = [];
for ($i = $from; $i <= $to; $i++) {
    if ($i == 246) {
        echo "No output at all!";
    }
    if ($i == 250) {
        echo "Still no output...";
    }
    if ($i == 256) {
        echo "Still no output...";
    }
    if ($i == 257) {
        echo "It works for {$i} and further numbers";
    }
    var_dump($i);
    $a[$i] = "test" . $i;
}
var_dump($a);
// array index number doesn't match the assigned value number (despite
$i is a float without a fractional part)
// also there is no element with index 256 in the $a array...

Expected result:
----------------
1)Equality operator should return true for all numbers within $from..$to
range
2)Array indexes should not be skipped during assigment

Actual result:
--------------
1)Equality operator returns false on ($i == number) when number is lower
than 257.
2)Array index number doesn't match the assigned $i value number
3)Index with number 256 was missed at all in the $a array

-- 
Edit bug report at https://bugs.php.net/bug.php?id=73358&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=73358&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=73358&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=73358&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=73358&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=73358&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=73358&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=73358&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=73358&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=73358&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=73358&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=73358&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=73358&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=73358&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73358&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=73358&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=73358&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=73358&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73358&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=73358&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=73358&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#204936) next »