# HG changeset patch # User John W. Eaton # Date 1202804861 18000 # Node ID 83f4996e8d01d0ef8156c611cb300158119cf0ff # Parent a3710cf0b0104cc218d8bc5e32073631c4aa9cd1 fix for loop iteration limit bug with ranges diff -r a3710cf0b010 -r 83f4996e8d01 src/ChangeLog --- a/src/ChangeLog Fri Feb 08 03:43:53 2008 -0500 +++ b/src/ChangeLog Tue Feb 12 03:27:41 2008 -0500 @@ -1,3 +1,8 @@ +2008-02-12 John W. Eaton + + * pt-loop.cc (tree_simple_for_command::eval): Compute range + element with multiplication. + 2008-02-08 John W. Eaton * ov-struct.cc (octave_struct::subsref): Allow Cell::index to resize. diff -r a3710cf0b010 -r 83f4996e8d01 src/pt-loop.cc --- a/src/pt-loop.cc Fri Feb 08 03:43:53 2008 -0500 +++ b/src/pt-loop.cc Tue Feb 12 03:27:41 2008 -0500 @@ -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);