php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72017 range() with float step produces unexpected result
Submitted: 2016-04-13 16:15 UTC Modified: 2016-05-16 21:21 UTC
From: contact at rarst dot net Assigned: tpunt (profile)
Status: Closed Package: Arrays related
PHP Version: 7.0.5 OS: Windows 7 x64
Private report: No CVE-ID: None
 [2016-04-13 16:15 UTC] contact at rarst dot net
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)
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-13 16:44 UTC] pollita@php.net
-Assigned To: +Assigned To: tpunt
 [2016-05-16 21:21 UTC] ab@php.net
-Status: Assigned +Status: Closed
 [2016-05-16 21:21 UTC] ab@php.net
Fixed by the PR https://github.com/php/php-src/pull/1863

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC