Bug #80912 [Opn->Nab]: wrong range() result
| From: | requinix@php.net | Date: | Sun, 28 Mar 2021 10:12:56 +0000 |
| Subject: | Bug #80912 [Opn->Nab]: wrong range() result | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233030@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80912&edit=1
ID: 80912
Updated by: requinix@php.net
Reported by: np25071984 at gmail dot com
Summary: wrong range() result
-Status: Open
+Status: Not a bug
Type: Bug
Package: Math related
Operating System: mac os Darwin
PHP Version: 8.0.3
Block user comment: N
Private report: N
New Comment:
Floating point values have a limited precision. Hence a value might
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly
printing it without any mathematical operations.
If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/
Thank you for your interest in PHP.
Previous Comments:
------------------------------------------------------------------------
[2021-03-28 07:28:44] np25071984 at gmail dot com
Description:
------------
Since version 7.0.3 I get wrong result (without the last element).
Test script:
---------------
var_dump(range( 0.1, 1.2, 0.1 ));
Expected result:
----------------
array(12) {
[0]=>
float(0.1)
[1]=>
float(0.2)
[2]=>
float(0.3)
[3]=>
float(0.4)
[4]=>
float(0.5)
[5]=>
float(0.6)
[6]=>
float(0.7)
[7]=>
float(0.8)
[8]=>
float(0.9)
[9]=>
float(1)
[10]=>
float(1.1)
[10]=>
float(1.2)
}
Actual result:
--------------
array(11) {
[0]=>
float(0.1)
[1]=>
float(0.2)
[2]=>
float(0.3)
[3]=>
float(0.4)
[4]=>
float(0.5)
[5]=>
float(0.6)
[6]=>
float(0.7)
[7]=>
float(0.8)
[8]=>
float(0.9)
[9]=>
float(1)
[10]=>
float(1.1)
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80912&edit=1