diff options
author | Adam Harvey <aharvey@php.net> | 2011-04-06 10:23:06 +0000 |
---|---|---|
committer | Adam Harvey <aharvey@php.net> | 2011-04-06 10:23:06 +0000 |
commit | 840308cfd097ed85bbd3e3c6d6d67671855a463d (patch) | |
tree | e4197c54d01f60d74495642e8b11f86108323a71 /ext/standard/array.c | |
parent | f9721d03f7caee2d87f22893b69f46f6c98ed3a0 (diff) | |
download | php-git-840308cfd097ed85bbd3e3c6d6d67671855a463d.tar.gz |
Implement FR #54459 (Range function accuracy) by changing the way range()
calculates values when used with floating point bounds/step.
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r-- | ext/standard/array.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c index ac2e49245a..3421fc0b84 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1688,28 +1688,32 @@ PHP_FUNCTION(range) } } else if (Z_TYPE_P(zlow) == IS_DOUBLE || Z_TYPE_P(zhigh) == IS_DOUBLE || is_step_double) { - double low, high; + double low, high, value; + long i; double_str: convert_to_double(zlow); convert_to_double(zhigh); low = Z_DVAL_P(zlow); high = Z_DVAL_P(zhigh); + i = 0; if (low > high) { /* Negative steps */ if (low - high < step || step <= 0) { err = 1; goto err; } - for (; low >= (high - DOUBLE_DRIFT_FIX); low -= step) { - add_next_index_double(return_value, low); + + for (value = low; value >= (high - DOUBLE_DRIFT_FIX); value = low - (++i * step)) { + add_next_index_double(return_value, value); } } else if (high > low) { /* Positive steps */ if (high - low < step || step <= 0) { err = 1; goto err; } - for (; low <= (high + DOUBLE_DRIFT_FIX); low += step) { - add_next_index_double(return_value, low); + + for (value = low; value <= (high + DOUBLE_DRIFT_FIX); value = low + (++i * step)) { + add_next_index_double(return_value, value); } } else { add_next_index_double(return_value, low); |