diff liboctave/array/Range.h @ 16169:0303fda3e929

Fix range behavior with -0 endpoints (bug #38423) * libinterp/interpfcn/pr-output.cc(octave_print_internal): print base or limit of range rather than using expression base+i*increment which can destroy the signbit of base/limit. * liboctave/array/Range.cc(Range constructor): Move trivial 2-line constructor to .h file. * liboctave/array/Range.cc(matrix_value, checkelem): Return base for first element of array. Return limit of range for end of array if appropriate. * liboctave/array/Range.cc(elem): Move function from Range.h Return base for first element of array. Return limit of range for end of array if appropriate. * liboctave/array/Range.cc(_rangeindex_helper, index): Return base for first element of array. Return limit of range for end of array if appropriate. * liboctave/array/Range.cc(min, max): Use '<=' or '>=' tests to return base or limit if appropriate. * liboctave/array/Range.cc(is_sorted): Place more common test first in if/else if/else tree. * liboctave/array/Range.cc(operator <<): Return base for first element of array. Return limit of range for end of array if appropriate. liboctave/array/Range.h(Range constructor): Put trivial 2-line constructor in .h file. liboctave/array/Range.h(elem): Move function which has become more complicated to Range.cc. * test/range.tst: Add %!tests for corner cases of base and limit of range.
author Rik <rik@octave.org>
date Fri, 01 Mar 2013 14:06:02 -0800
parents 648dabbb4c6b
children d63878346099
line wrap: on
line diff
--- a/liboctave/array/Range.h	Fri Mar 01 12:46:56 2013 -0800
+++ b/liboctave/array/Range.h	Fri Mar 01 14:06:02 2013 -0800
@@ -50,7 +50,13 @@
       rng_nelem (nelem_internal ()), cache () { }
 
   // For operators' usage (to preserve element count).
-  Range (double b, double i, octave_idx_type n);
+  Range (double b, double i, octave_idx_type n)
+    : rng_base (b), rng_limit (b + (n-1) * i), rng_inc (i),
+      rng_nelem (n), cache ()
+    {
+      if (! xfinite (b) || ! xfinite (i))
+        rng_nelem = -2;
+    }
 
   double base (void) const { return rng_base; }
   double limit (void) const { return rng_limit; }
@@ -80,14 +86,7 @@
 
   double checkelem (octave_idx_type i) const;
 
-  double elem (octave_idx_type i) const
-    {
-#if defined (BOUNDS_CHECKING)
-      return checkelem (i);
-#else
-      return rng_base + rng_inc * i;
-#endif
-    }
+  double elem (octave_idx_type i) const;
 
   Array<double> index (const idx_vector& i) const;