#50679 [Opn->Bgs]: range fails on some float values
| From: | jani@php.net | Date: | Wed, 06 Jan 2010 20:31:42 +0000 |
| Subject: | #50679 [Opn->Bgs]: range fails on some float values | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-146398@lists.php.net to get a copy of this message | ||
ID: 50679
Updated by: jani@php.net
Reported By: kauffj at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: Ubuntu 9.10
PHP Version: 5.3.1
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://docs.sun.com/source/806-3568/ncg_goldberg.html
Thank you for your interest in PHP.
Previous Comments:
------------------------------------------------------------------------
[2010-01-06 16:07:12] kauffj at gmail dot com
Description:
------------
The range function works on some float values but not others.
Reproduce code:
---------------
WORKS: print_r(range(0.3, 0.4, 0.1));
FAILS: print_r(range(5.5, 5.6, 0.1));
WORKS: print_r(range(5.5, 5.7, 0.1));
Expected result:
----------------
Array
(
[0] => 0.3
[1] => 0.4
)
Array
(
[0] => 5.5
[1] => 5.6
)
Array
(
[0] => 5.5
[1] => 5.6
[2] => 5.7
)
Actual result:
--------------
Array
(
[0] => 0.3
[1] => 0.4
)
PHP Warning: range(): step exceeds the specified range
Array
(
[0] => 5.5
[1] => 5.6
[2] => 5.7
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50679&edit=1