Mercurial > hg > octave-lyh
comparison 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 |
comparison
equal
deleted
inserted
replaced
16168:8650eec57e9f | 16169:0303fda3e929 |
---|---|
48 Range (double b, double l, double i) | 48 Range (double b, double l, double i) |
49 : rng_base (b), rng_limit (l), rng_inc (i), | 49 : rng_base (b), rng_limit (l), rng_inc (i), |
50 rng_nelem (nelem_internal ()), cache () { } | 50 rng_nelem (nelem_internal ()), cache () { } |
51 | 51 |
52 // For operators' usage (to preserve element count). | 52 // For operators' usage (to preserve element count). |
53 Range (double b, double i, octave_idx_type n); | 53 Range (double b, double i, octave_idx_type n) |
54 : rng_base (b), rng_limit (b + (n-1) * i), rng_inc (i), | |
55 rng_nelem (n), cache () | |
56 { | |
57 if (! xfinite (b) || ! xfinite (i)) | |
58 rng_nelem = -2; | |
59 } | |
54 | 60 |
55 double base (void) const { return rng_base; } | 61 double base (void) const { return rng_base; } |
56 double limit (void) const { return rng_limit; } | 62 double limit (void) const { return rng_limit; } |
57 double inc (void) const { return rng_inc; } | 63 double inc (void) const { return rng_inc; } |
58 octave_idx_type nelem (void) const { return rng_nelem; } | 64 octave_idx_type nelem (void) const { return rng_nelem; } |
78 | 84 |
79 // Support for single-index subscripting, without generating matrix cache. | 85 // Support for single-index subscripting, without generating matrix cache. |
80 | 86 |
81 double checkelem (octave_idx_type i) const; | 87 double checkelem (octave_idx_type i) const; |
82 | 88 |
83 double elem (octave_idx_type i) const | 89 double elem (octave_idx_type i) const; |
84 { | |
85 #if defined (BOUNDS_CHECKING) | |
86 return checkelem (i); | |
87 #else | |
88 return rng_base + rng_inc * i; | |
89 #endif | |
90 } | |
91 | 90 |
92 Array<double> index (const idx_vector& i) const; | 91 Array<double> index (const idx_vector& i) const; |
93 | 92 |
94 void set_base (double b) | 93 void set_base (double b) |
95 { | 94 { |