Skip to content

Commit

Permalink
Merge pull request adafruit#8946 from kbsriram/main
Browse files Browse the repository at this point in the history
Add tests for bit_length()
  • Loading branch information
jepler authored Feb 18, 2024
2 parents 6c1e34e + e675ea3 commit 8728c6d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/basics/int_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# CIRCUITPY-CHANGE
# test bit_length for various sizes of ints

for x in range(-10, 10):
print(x.bit_length())

for i in [2, 3, 15, 16, 17, 31, 32, 33, 63, 64, 234]:
a = 2**i
print((a - 1).bit_length())
print((1 - a).bit_length())
print(a.bit_length())
print((-a).bit_length())
print((a + 1).bit_length())
print((-a - 1).bit_length())
# Ensure transitioning between small and large int representations
# still work.
print((a - a).bit_length())
print((0 * a).bit_length())
print((0 * a - 1).bit_length())
print((0 * a + 1).bit_length())
print((2 * a).bit_length())
print((2 * a + 1).bit_length())
print((2 * a - 1).bit_length())

0 comments on commit 8728c6d

Please sign in to comment.