GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-119714: Add PyLong_GetNumBits() function by vstinner · Pull Request #119715 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented May 29, 2024 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: [C API] Add PyLong_GetNumBits() function #119714

📚 Documentation preview 📚: https://cpython-previews--119715.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added the awaiting core review label May 29, 2024
@bedevere-app bedevere-app Bot mentioned this pull request May 29, 2024
[C API] Add PyLong_GetNumBits() function #119714
Closed
@vstinner vstinner mentioned this pull request Jun 3, 2024
Add PyLong_GetNumBits() function capi-workgroup/decisions#28
Closed
erlend-aasland
erlend-aasland reviewed Jun 3, 2024
View reviewed changes
Comment thread Doc/c-api/long.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Include/cpython/longobject.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_capi/test_long.py
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)

@erlend-aasland erlend-aasland Jun 3, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Jun 3, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
erlend-aasland
erlend-aasland reviewed Jun 3, 2024
View reviewed changes
Comment thread Doc/c-api/long.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

vstinner and others added 6 commits June 3, 2024 14:25
@vstinner
pythongh-119714: Add PyLong_GetNumBits() function
0b46817
@vstinner
Suggest calling the bit_length() method
9481136
@vstinner @erlend-aasland
Update Doc/c-api/long.rst
c1f6310
Co-authored-by: Erlend E. Aasland <[email protected]>
@vstinner @erlend-aasland
Update Include/cpython/longobject.h
fd8a3f2
Co-authored-by: Erlend E. Aasland <[email protected]>
@vstinner
Add OverflowError test
afc665e
@vstinner
doc: add link to int.bit_length() method
b08d260
@vstinner
vstinner force-pushed the long_numbits branch from 13ef292 to b08d260 Compare June 3, 2024 12:26
@vstinner

vstinner commented Jun 3, 2024

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Jun 20, 2024

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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

Reviewers

@erlend-aasland erlend-aasland erlend-aasland left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting core review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@vstinner @erlend-aasland
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.