You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2012-07-19.00:17:45.583>created_at=<Date2012-07-18.23:32:22.303>labels= ['invalid', 'type-feature', 'library']
title='Add bitlength function to the math module'updated_at=<Date2012-07-20.11:51:13.119>user='https://bugs.python.org/anon'
Many numeric algorithms require knowing the number of bits an integer has (for instance integer squareroots). For example this simple algorithm using shifts is O(n^2):
It should be possible find the bit-length of an integer in O(1) however. O(n) algorithms with high constants simply don't cut it for many applications.
That's why I would propose adding an inbuilt function bitlength(n) to the math module. bitlength(n) would be the integer satisfying
bitlength(n) = ceil(log2(abs(n)+1))
Python more than ever with PyPy progressing is becoming a great platform for mathematical computation. This is an important building block for a huge number of algorithms but currently has no elegant or efficient solution in plain Python.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: