Mercurial > hg > octave-lyh
changeset 11634:83f4996e8d01 release-3-0-x
fix for loop iteration limit bug with ranges
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 12 Feb 2008 03:27:41 -0500 |
parents | a3710cf0b010 |
children | e08d2fff0d58 |
files | src/ChangeLog src/pt-loop.cc |
diffstat | 2 files changed, 16 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2008-02-12 John W. Eaton <jwe@octave.org> + + * pt-loop.cc (tree_simple_for_command::eval): Compute range + element with multiplication. + 2008-02-08 John W. Eaton <jwe@octave.org> * ov-struct.cc (octave_struct::subsref): Allow Cell::index to resize.
--- 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);