Skip to content
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

gh-119714: Add PyLong_GetNumBits() function #119715

Closed
wants to merge 6 commits into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented May 29, 2024

Doc/c-api/long.rst Outdated Show resolved Hide resolved
Include/cpython/longobject.h Outdated Show resolved Hide resolved
Comment on lines +726 to +747
self.assertEqual(numbits(0), 0)
self.assertEqual(numbits(7), 3)
self.assertEqual(numbits(-37), 6)
self.assertEqual(numbits(684_643_661_981), 40)
self.assertEqual(numbits(2**123-1), 123)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no tests for the two overflow cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test, but it requires 1145324612.3 GiB of memory to run :-) On 32-bit systems, the test pass and only requires 273 MiB.

Doc/c-api/long.rst Outdated Show resolved Hide resolved
@vstinner
Copy link
Member Author

vstinner commented Jun 3, 2024

PR rebased to fix merge conflicts with the main branch (with the new PyLong_GetSign() function).

@vstinner
Copy link
Member Author

The C API Working Group rejected this API: PyLong_AsNativeBytes() should be used instead.

@vstinner vstinner closed this Jun 20, 2024
@vstinner vstinner deleted the long_numbits branch June 20, 2024 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants