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 {




-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to