[libcxx-commits] [PATCH] D99520: [libcxx] Convert the result of math.floor to int

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 29 11:03:14 PDT 2021


Quuxplusone requested changes to this revision.
Quuxplusone added inline comments.
This revision now requires changes to proceed.


================
Comment at: libcxx/utils/gdb/libcxx/printers.py:442
         for bit in range(self.bit_count):
-            word = math.floor(bit / self.bits_per_word)
+            word = int(math.floor(bit / self.bits_per_word))
             word_bit = 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.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99520/new/

https://reviews.llvm.org/D99520



More information about the libcxx-commits mailing list