Bug #75310 [Opn->Nab]: range(0.94, 0.49, -0.01) difference

From: Date: Wed, 04 Oct 2017 19:55:14 +0000
Subject: Bug #75310 [Opn->Nab]: range(0.94, 0.49, -0.01) difference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211507@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75310&edit=1 ID: 75310 Updated by: requinix@php.net Reported by: shawn at mckenzies dot net Summary: range(0.94, 0.49, -0.01) difference -Status: Open +Status: Not a bug Type: Bug Package: Arrays related Operating System: Win,Linux PHP Version: 7.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. PHP can't really guarantee any particular behavior; pick different pairs of numbers and you'll get different results. https://3v4l.org/JtEG9 Previous Comments: ------------------------------------------------------------------------ [2017-10-04 19:49:16] shawn at mckenzies dot net Seems to have been introduced in 7.0.3. ------------------------------------------------------------------------ [2017-10-04 19:43:52] shawn at mckenzies dot net Description: ------------ range(0.94, 0.49, -0.01) returns a 45 element array from .94 to .5 in PHP 7.0.3 - 7.2.0rc2 but returns the expected 46 element array .94 to .49 in PHP 5.6.0 - 5.6.30. Test script: --------------- https://3v4l.org/gZ3cs#v703 $a = range(0.94, 0.49, -0.01); echo count($a).PHP_EOL; echo min($a).PHP_EOL; print_r($a); Expected result: ---------------- Same array should be created created across PHP versions. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75310&edit=1

« previous php.bugs (#211507) next »