php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38038 range() gives back wrong values
Submitted: 2006-07-08 10:49 UTC Modified: 2006-07-08 11:03 UTC
From: mcboog at zonnet dot nl Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5CVS-2006-07-08 (snap) OS: Windows XP Prof
Private report: No CVE-ID: None
 [2006-07-08 10:49 UTC] mcboog at zonnet dot nl
Description:
------------
range() gives back wrong values.

Reproduce code:
---------------
<?php

$scaleMin = -0.6;
$scaleMax = 0;
$scaleStep = 0.1;
$range = range($scaleMin, $scaleMax, $scale);
print $range[6];

?>

Expected result:
----------------
0

Actual result:
--------------
-2.7755575615629E-017

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-08 11:03 UTC] tony2001@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 18:01:32 2024 UTC