Mercurial > hg > octave-nkf
diff liboctave/array/Range.h @ 19042:47d4b680d0e0
improve accuracy of range/scalar arithmetic (bug #42589)
* Range.h, Range.cc (Range::Range (double, double, double,
octave_idx_type): New protected constructor.
(operator -, operator +, operator *): Use new constructor.
(Range::Range (double, double, octave_idx_type): Also check that the
limit remains finite.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 20 Jun 2014 18:55:38 -0400 |
parents | 49a5a4be04a1 |
children | d60b44acfff7 |
line wrap: on
line diff
--- a/liboctave/array/Range.h +++ b/liboctave/array/Range.h @@ -54,7 +54,7 @@ : rng_base (b), rng_limit (b + (n-1) * i), rng_inc (i), rng_nelem (n), cache () { - if (! xfinite (b) || ! xfinite (i)) + if (! xfinite (b) || ! xfinite (i) | ! xfinite (rng_limit)) rng_nelem = -2; } @@ -145,6 +145,16 @@ void clear_cache (void) const { cache.resize (0, 0); } +protected: + + // For operators' usage (to allow all values to be set directly). + Range (double b, double l, double i, octave_idx_type n) + : rng_base (b), rng_limit (l), rng_inc (i), + rng_nelem (n), cache () + { + if (! xfinite (b) || ! xfinite (i) || ! xfinite (l)) + rng_nelem = -2; + } }; extern OCTAVE_API Range operator - (const Range& r);