Bug #72017 [NEW]: range() with float step produces unexpected result
| From: | contact at rarst dot net | Date: | Wed, 13 Apr 2016 16:15:21 +0000 |
| Subject: | Bug #72017 [NEW]: range() with float step produces unexpected result | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-200528@lists.php.net to get a copy of this message | ||
From: contact at rarst dot net
Operating system: Windows 7 x64
PHP version: 7.0.5
Package: Arrays related
Bug Type: Bug
Bug description:range() with float step produces unexpected result
Description:
------------
Running this call
range( 4.5, 4.2, 0.1 ) with these specific numbers
(discovered empirically, other ranges might not demonstrate the issue).
I expect result to be: array(4) 4.5, 4.4, 4.3, 4.2
I observe result to be: array(3) 4.5, 4.4, 4.3
I've run this in online checker and it reported expected result up to
version 7.0.2 and unexpected result starting from 7.0.3, see
https://3v4l.org/BbS2k
Test script:
---------------
var_dump( range( 4.5, 4.2, 0.1 ) );
Expected result:
----------------
array(4) {
[0]=>
float(4.5)
[1]=>
float(4.4)
[2]=>
float(4.3)
[3]=>
float(4.2)
}
Actual result:
--------------
array(3) {
[0]=>
float(4.5)
[1]=>
float(4.4)
[2]=>
float(4.3)
}
--
Edit bug report at https://bugs.php.net/bug.php?id=72017&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72017&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72017&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72017&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72017&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72017&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72017&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72017&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72017&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72017&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72017&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72017&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72017&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72017&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72017&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72017&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72017&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72017&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72017&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72017&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72017&r=mysqlcfg