diff libinterp/octave-value/ov.cc @ 29353:715344f405f0

improve handling of nan, infinite value, and empty ranges (bug #59229) All ranges with NaN as their base, limit, or increment should produce a single NaN value. Ranges with infinite base, limit, or increment values may be empty, or produce NaN, or an infinite number of elements. For compatibility with Matlab, ranges constructed normally in the interpreter with an increment of zero are emtpy. We still provide a special constructor to allow a range with zero increment to represent a row vector with a constant value. * Range.h, Range.cc (xall_elements_re_ints): Handle NaN and inf ranges. (xinit): Correctly handle NaN ranges, empty ranges, and ranges with an infinite number of values. (xis_storable): New function. (range<T>::is_storable): New function with specializations for double and float. (range<T>::array_value): If number of elements is 1, reeturn final value. (range<T>::checkelem, range<T>::elem): If number of elements is 1 and index is 0, Return final value instead of base value. (class rangeidx_helper): Likewise. Prefix data members with m_. * ov-base.h (octave_base_value::is_storable): New virtual function. * ov-magic-int.h (octave_base_magic_int::is_storable): New function. * ov-null-mat.h (octave_null_matrix::is_storable, octave_null_str::is_storable, octave_null_sq_str::is_storable): New functions. * ov-range.h (octave_range::is_storable): New function. * ov.cc (octave_value::storable_value, octave_value::make_storable_value): Error if range is not storable. * test/range.tst: New tests for double and float ranges.
author John W. Eaton <jwe@octave.org>
date Sat, 06 Feb 2021 09:27:26 -0500
parents 8f67ad8b3103
children 7854d5752dd2
line wrap: on
line diff
--- a/libinterp/octave-value/ov.cc	Fri Feb 05 14:03:27 2021 -0500
+++ b/libinterp/octave-value/ov.cc	Sat Feb 06 09:27:26 2021 -0500
@@ -2246,6 +2246,8 @@
     retval = octave_value (rep->empty_clone ());
   else if (is_magic_int ())
     retval = octave_value (rep->double_value ());
+  else if (is_range () && ! rep->is_storable ())
+    error ("range with infinite number of elements cannot be stored");
   else
     retval.maybe_economize ();
 
@@ -2269,6 +2271,8 @@
         delete rep;
       rep = rc;
     }
+  else if (is_range () && ! rep->is_storable ())
+    error ("range with infinite number of elements cannot be stored");
   else
     maybe_economize ();
 }