Bug #68330 [Opn->Nab]: Problem with range function and float

From: Date: Thu, 30 Oct 2014 16:16:23 +0000
Subject: Bug #68330 [Opn->Nab]: Problem with range function and float
References: 1  Groups: php.standards 
Request: Send a blank email to standards-+get-538@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68330&edit=1 ID: 68330 Updated by: ajf@php.net Reported by: gcrispyn at assessfirst dot com Summary: Problem with range function and float -Status: Open +Status: Not a bug Type: Bug Package: PHP Language Specification Operating System: Linux PHP Version: 5.5.18 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2014-10-30 15:44:04] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68330&edit=1

« previous php.standards (#538) next »