Mercurial > jwe > octave
changeset 28642:fb37f50d5ba8
new Range::final_value function
* Range.h (Range::final_value): New function.
* pr-output.cc (octave_print_internal (std::ostream&, const Range&,
bool, int)): Use Range::final_value instead of computing it here.
* xpow.cc (elem_expow (double, const Range&)): Likewise.
(elem_expow (const Complex&, const Range&)): Likewise.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 06 Aug 2020 15:36:30 -0400 |
parents | a3db48e66ef8 |
children | 98192ec1621f |
files | libinterp/corefcn/pr-output.cc libinterp/corefcn/xpow.cc liboctave/array/Range.h |
diffstat | 3 files changed, 13 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.cc Thu Aug 06 15:09:30 2020 -0400 +++ b/libinterp/corefcn/pr-output.cc Thu Aug 06 15:36:30 2020 -0400 @@ -2494,6 +2494,7 @@ double base = r.base (); double increment = r.increment (); double limit = r.limit (); + double final_value = r.final_value (); octave_idx_type num_elem = r.numel (); if (plus_format && ! pr_as_read_syntax) @@ -2575,12 +2576,7 @@ val = base + i * increment; if (i == num_elem - 1) - { - // See the comments in Range::matrix_value. - if ((increment > 0 && val >= limit) - || (increment < 0 && val <= limit)) - val = limit; - } + val = final_value; os << " ";
--- a/libinterp/corefcn/xpow.cc Thu Aug 06 15:09:30 2020 -0400 +++ b/libinterp/corefcn/xpow.cc Thu Aug 06 15:36:30 2020 -0400 @@ -732,8 +732,7 @@ } else { - // Don't use Range::limit () here. - double limit = std::pow (a, r.base () + (n-1) * r.increment ()); + double limit = std::pow (a, r.final_value ()); double inc = std::pow (a, -r.increment ()); result(n-1) = limit; for (octave_idx_type i = n-2; i >= 0; i--) @@ -962,8 +961,7 @@ } else { - // Don't use Range::limit () here. - Complex limit = std::pow (a, r.base () + (n-1) * r.increment ()); + Complex limit = std::pow (a, r.final_value ()); Complex inc = std::pow (a, -r.increment ()); result(n-1) = limit; for (octave_idx_type i = n-2; i >= 0; i--)
--- a/liboctave/array/Range.h Thu Aug 06 15:09:30 2020 -0400 +++ b/liboctave/array/Range.h Thu Aug 06 15:36:30 2020 -0400 @@ -414,6 +414,15 @@ double inc (void) const { return m_inc; } double increment (void) const { return m_inc; } + // We adjust the limit to be the final value, so return that. We + // could introduce a new variable to store the final value separately, + // but it seems like that would just add confusion. If we changed + // the meaning of the limit function, we would change the behavior of + // programs that expect limit to be the final value instead of the + // value of the limit when the range was created. This problem will + // be fixed with the new template range class. + double final_value (void) const { return m_limit; } + octave_idx_type numel (void) const { return m_numel; } dim_vector dims (void) const { return dim_vector (1, m_numel); }