core: add int.bit_length()#2824
Closed
jepler wants to merge 1 commit into
Closed
Conversation
Author
|
I see the tests failed. It's another expected change, but for some reason I didn't encounter it locally. If there's interest in seeing this included, I'll fix it up. Otherwise, we can just close this and leave it for posterity. @tannewt thoughts? |
Member
|
My feeling is that it shouldn't be included. A helper python function can always do it and it wouldn't take up the flash space. (Lower power is out of space on two boards now which has me wary of adding else to the core objects.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
CPython has
int.bit_length(), which returns the length of the number in bits.I wanted this because it was required by a Fibonacci number calculator I wrote. However, as evidenced by the fact that upstream micropython hasn't implemented it either, I doubt it has wide applicability, so I won't be too sad if it's not incorporated.
On a CLUE I can calculate (and even print in decimal!)
fib(65000)which is 13585 decimal digits long. The calculation takes about 9 seconds. Much larger than this, and the internal RAM is exhausted.The program uses the matrix representation of the Fibonacci sequence, so that a result can be found by raising a matrix to a power, instead of by calculating sequentially all the numbers in the sequence up to the requested one.
I do not know why the updated
builtin_help.py.expremoves two functions from the micropython module. It's unexpected by me.