Mercurial > hg > octave-lyh
diff src/pt-loop.cc @ 7469:360b4f7684fd
fix for loop iteration limit bug with ranges
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 12 Feb 2008 03:15:49 -0500 |
parents | 745a8299c2b5 |
children | 71f068b22fcc |
line wrap: on
line diff
--- a/src/pt-loop.cc +++ b/src/pt-loop.cc @@ -357,13 +357,21 @@ double b = rng.base (); double increment = rng.inc (); bool quit = false; - double tmp_val = b; - for (octave_idx_type i = 0; i < steps; i++, tmp_val += increment) + for (octave_idx_type i = 0; i < steps; i++) { MAYBE_DO_BREAKPOINT; - octave_value val (tmp_val); + // Use multiplication here rather than declaring a + // temporary variable outside the loop and using + // + // tmp_val += increment + // + // to avoid problems with limited precision. Also, this + // is consistent with the way Range::matrix_value is + // implemented. + + octave_value val (b + i * increment); do_for_loop_once (ult, val, quit);