php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68330 Problem with range function and float
Submitted: 2014-10-30 15:44 UTC Modified: 2014-10-30 18:10 UTC
From: gcrispyn at assessfirst dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.5.18 OS: Linux
Private report: No CVE-ID: None
 [2014-10-30 15:44 UTC] gcrispyn at assessfirst dot com
Description:
------------
When you want to know if (float)7.8 value is in the range between 7 and 10 with a step of 0.1, the result is false. But, when you use the same function with a range between 6 and 10, the result is true.

Expected result:
----------------
var_dump(in_array(7.8, range(6, 10, .1))); --> true
var_dump(in_array(7.8, range(7, 10, .1))); --> true

Actual result:
--------------
var_dump(in_array(7.8, range(6, 10, .1))); --> true
var_dump(in_array(7.8, range(7, 10, .1))); --> false

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-30 16:16 UTC] ajf@php.net
-Status: Open +Status: Not a bug
 [2014-10-30 16:16 UTC] ajf@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Floating point values are known to be inaccurate. The manual states you shouldn't try to check for equality.
 [2014-10-30 18:10 UTC] stas@php.net
-Package: PHP Language Specification +Package: Unknown/Other Function
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 12:01:27 2024 UTC