changeset 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 85be2610d6e3
children ada435261879
files src/ChangeLog src/pt-loop.cc
diffstat 2 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Feb 12 03:09:44 2008 -0500
+++ b/src/ChangeLog	Tue Feb 12 03:15:49 2008 -0500
@@ -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-11  John W. Eaton  <jwe@octave.org>
 
 	* Makefile.in ($(MAKEDEPS)): Skip dependencies if omit_deps is defined.
--- a/src/pt-loop.cc	Tue Feb 12 03:09:44 2008 -0500
+++ b/src/pt-loop.cc	Tue Feb 12 03:15:49 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);