Mercurial > hg > octave-kai
changeset 8589:0131fa223dbc
make length invariant in range-scalar ops
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 26 Jan 2009 07:49:04 +0100 |
parents | 79845b1793cf |
children | c136d313206a |
files | liboctave/Range.cc liboctave/Range.h |
diffstat | 2 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Range.cc +++ b/liboctave/Range.cc @@ -291,37 +291,37 @@ Range operator - (const Range& r) { - return Range (-r.base (), -r.limit (), -r.inc ()); + return Range (-r.base (), -r.inc (), r.nelem ()); } Range operator + (double x, const Range& r) { - return Range (x + r.base (), x + r.limit (), r.inc ()); + return Range (x + r.base (), r.inc (), r.nelem ()); } Range operator + (const Range& r, double x) { - return Range (r.base () + x, r.limit () + x, r.inc ()); + return Range (r.base () + x, r.inc (), r.nelem ()); } Range operator - (double x, const Range& r) { - return Range (x - r.base (), x - r.limit (), -r.inc ()); + return Range (x - r.base (), -r.inc (), r.nelem ()); } Range operator - (const Range& r, double x) { - return Range (r.base () - x, r.limit () - x, r.inc ()); + return Range (r.base () - x, r.inc (), r.nelem ()); } Range operator * (double x, const Range& r) { - return Range (x * r.base (), x * r.limit (), x * r.inc ()); + return Range (x * r.base (), x * r.inc (), r.nelem ()); } Range operator * (const Range& r, double x) { - return Range (r.base () * x, r.limit () * x, r.inc () * x); + return Range (r.base () * x, r.inc () * x, r.nelem ()); }
--- a/liboctave/Range.h +++ b/liboctave/Range.h @@ -50,6 +50,11 @@ : rng_base (b), rng_limit (l), rng_inc (i), rng_nelem (nelem_internal ()), cache () { } + // For operators' usage (to preserve element count). + Range (double b, double i, octave_idx_type n) + : rng_base (b), rng_limit (b + n * i), rng_inc (i), + rng_nelem (n), cache () { } + double base (void) const { return rng_base; } double limit (void) const { return rng_limit; } double inc (void) const { return rng_inc; }