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 | 187eb235fecce05cbc6426322f6792363f1650f2 (patch) | |
| tree | df7f28b1251778246d7ead6768537a48ca8f59d2 /ext/standard/array.c | |
| parent | 18d71a6f5911d36f4310e160fa8ad0d4106474cd (diff) | |
| download | php-git-187eb235fecce05cbc6426322f6792363f1650f2.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 a2dc8c82cb..ed967e3395 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1692,28 +1692,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); |
