[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #62968] idx_vector constructor m_len calculati
From: |
Markus Mützel |
Subject: |
[Octave-bug-tracker] [bug #62968] idx_vector constructor m_len calculation is incorrect |
Date: |
Sat, 27 Aug 2022 10:15:54 -0400 (EDT) |
Update of bug #62968 (project octave):
Status: None => Need Info
Operating System: GNU/Linux => Any
Summary: idx_vector constructor m_len calculation is incorret
=> idx_vector constructor m_len calculation is incorrect
_______________________________________________________
Follow-up Comment #1:
Is `m_len` the number of elements in the idx_vector? (I think it is.) Is
`limit` included in the range? (Not sure if it is meant to be.)
Assuming both are true (I'm not sure if they are), let's check `idx_vector (0,
9, 1)` (corresponding to the index range `1:1:10` in an .m file?). That should
result in 10 elements IIUC. With your updated formula, that would result in
`(9 - 0 + 1 - 1) / 1` which is 9. (But it would also be 9 with the current
formula.)
Nevertheless, I can't quite figure out what that function is meant to do. And
there might be something wrong in its implementations.
Would the following change fix this?
diff -r 4c2b83516eb7 liboctave/array/idx-vector.cc
--- a/liboctave/array/idx-vector.cc Fri Aug 26 22:30:43 2022 +0200
+++ b/liboctave/array/idx-vector.cc Sat Aug 27 15:47:40 2022 +0200
@@ -103,7 +103,7 @@
octave_idx_type limit,
octave_idx_type step)
: idx_base_rep (), m_start(start),
- m_len (step ? std::max ((limit - start) / step,
+ m_len (step ? std::max ((limit - start) / step + 1,
static_cast<octave_idx_type> (0))
: -1),
m_step (step)
CC'ing jwe because he'll hopefully know what that function was meant to do.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?62968>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/