Mercurial > octave
diff liboctave/array/Range.h @ 30405:20cefb3b0da6 stable
range: Use specialization of init function for octave_int<T> types (bug #61300).
* liboctave/array/Range.h (range<T>::init): Revert to previous base
implementation. Use specialization for octave_int<T> types.
* liboctave/array/Range.cc (xinit<T>): Overload for octave_int<T> types.
(range<T>::init): Implement specialization for octave_int<T> types.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Mon, 29 Nov 2021 20:02:44 +0100 |
parents | f3f3e3793fb5 |
children | 4736bc8e9804 |
line wrap: on
line diff
--- a/liboctave/array/Range.h Tue Nov 30 08:54:58 2021 +0100 +++ b/liboctave/array/Range.h Mon Nov 29 20:02:44 2021 +0100 @@ -323,15 +323,11 @@ void init (void) { - // We need an integer division that is truncating decimals instead of - // rounding. So, use underlying C++ types instead of octave_int<T>. - // FIXME: The numerator might underflow or overflow. Add checks for that. m_numel = ((m_increment == T (0) || (m_limit > m_base && m_increment < T (0)) || (m_limit < m_base && m_increment > T (0))) - ? 0 - : (m_limit.value () - m_base.value () + m_increment.value ()) - / m_increment.value ()); + ? T (0) + : (m_limit - m_base + m_increment) / m_increment); m_final = m_base + (m_numel - 1) * m_increment; } @@ -344,6 +340,14 @@ template <> OCTAVE_API void range<double>::init (void); template <> OCTAVE_API void range<float>::init (void); + template <> OCTAVE_API void range<octave_int8>::init (void); + template <> OCTAVE_API void range<octave_int16>::init (void); + template <> OCTAVE_API void range<octave_int32>::init (void); + template <> OCTAVE_API void range<octave_int64>::init (void); + template <> OCTAVE_API void range<octave_uint8>::init (void); + template <> OCTAVE_API void range<octave_uint16>::init (void); + template <> OCTAVE_API void range<octave_uint32>::init (void); + template <> OCTAVE_API void range<octave_uint64>::init (void); template <> OCTAVE_API bool range<double>::is_storable (void) const; template <> OCTAVE_API bool range<float>::is_storable (void) const;