Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:579 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48095 invoked from network); 2 Apr 2003 01:24:34 -0000 Received: from unknown (HELO pigeon.alphaweb.net) (64.142.6.229) by pb1.pair.com with SMTP; 2 Apr 2003 01:24:34 -0000 Received: from localhost ([127.0.0.1] helo=alphaweb.net ident=www-data) by pigeon.alphaweb.net with smtp (Exim 4.10) id 190Xlc-0001lV-00 for internals@lists.php.net; Tue, 01 Apr 2003 18:14:20 -0800 Received: from 169.229.139.92 (SquirrelMail authenticated user sarag) by webmailtest.golemon.com with HTTP; Tue, 1 Apr 2003 18:14:20 -0800 (PST) Message-ID: <4282.169.229.139.92.1049249660.squirrel@webmailtest.golemon.com> Date: Tue, 1 Apr 2003 18:14:20 -0800 (PST) To: X-Priority: 3 Importance: Normal X-MSMail-Priority: Normal Reply-To: pollita@php.net X-Mailer: SquirrelMail (version 1.2.7) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: range() [ext/standard/tests/array/range.phpt] From: pollita@php.net ("Sara Golemon") This test is failing because of the good old-well known floating point drift issue. 4.9 + 0.1 > 5.0 The kludge attached below "solves" it, but... well... it's a kludge. It basicly adds (or subtracts) the smallest measurable piece of a double during the comparison step (so as to not alter the actual value) and give the step some room to breathe. Isn't there a better way to do it? Index: ext/standard/array.c =================================================================== RCS file: /repository/php4/ext/standard/array.c,v retrieving revision 1.224 diff -u -r1.224 array.c --- ext/standard/array.c 1 Apr 2003 21:47:21 -0000 1.224 +++ ext/standard/array.c 2 Apr 2003 01:17:29 -0000 @@ -81,6 +81,8 @@ #define INTERSECT_NORMAL 0 #define INTERSECT_ASSOC 1 +#define DOUBLE_DRIFT_FIX 0.000000000000001 + PHP_MINIT_FUNCTION(array) { #ifdef ZTS @@ -1543,7 +1545,7 @@ err = 1; goto err; } - for (; low >= high; low -= step) { + for (; low >= (high - DOUBLE_DRIFT_FIX); low -= step) { add_next_index_double(return_value, low); } } else if (high > low) { /* Positive steps */ @@ -1551,7 +1553,7 @@ err = 1; goto err; } - for (; low <= high; low += step) { + for (; low <= (high + DOUBLE_DRIFT_FIX); low += step) { add_next_index_double(return_value, low); } } else {