In Python 3, math.floor returns int when both arguments are ints.
In Python 2, math.floor returns float. This leads to a failure
because the result of math.floor is used as an array index. While
Python 2 is on its way out, it's still used in some places so use an
integer division instead.
Details
Details
- Reviewers
ldionne • Quuxplusone curdeius - Group Reviewers
Restricted Project - Commits
- rGbc4d3ca7bd44: [libcxx] Use integer division
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libcxx/utils/gdb/libcxx/printers.py | ||
---|---|---|
442 | Even better: word = int(bit / self.bits_per_word) Even more better: word = bit // self.bits_per_word |
Even better: word = int(bit / self.bits_per_word)
(Note that math.floor rounds upward when the argument is negative; but we don't ever expect the argument to be negative here, so "cast to int" is exactly the right semantics.)
Even more better: word = bit // self.bits_per_word
to just use integer division in the first place. This is the best option, because // (line 442) and % (line 443) go together nicely as a pair.