-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] feat: new primitive for int.bit_length
#19673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 15 commits
9e3d54a
24a7ae7
7dbbb77
b133de3
9d4116e
499bfb4
f718507
bb0a5eb
ae266ad
e83203b
1545a8d
0854952
1e10c40
be93fe7
d7b0a0c
1eb2c7e
71c30a0
37c6109
243cc9a
3f55d82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -572,3 +572,19 @@ class subc(int): | |
[file userdefinedint.py] | ||
class int: | ||
pass | ||
|
||
[case testBitLength] | ||
def bit_length(n: int) -> int: | ||
return n.bit_length() | ||
def test_bit_length() -> None: | ||
assert bit_length(0) == 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: This would be a bit more robust if you'd have say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well that's odd, I implemented the tests as you asked here but now we get segfaults on Python3.14 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also on the 32-bit test runner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay... well after implementing your bitscan idea the issue has resolved itself on python3.14... somehow I still don't understand how getattr(x, "bit_length")() would cause segfault behavior |
||
assert bit_length(1) == 1 | ||
assert bit_length(255) == 8 | ||
assert bit_length(256) == 9 | ||
assert bit_length(-256) == 9 | ||
# Large positive int | ||
assert bit_length(1 << 70) == 71 | ||
# Large negative int | ||
assert bit_length(-(1 << 70)) == 71 | ||
# Large int with all bits set | ||
assert bit_length((1 << 100) - 1) == 100 |
Uh oh!
There was an error while loading. Please reload this page.