-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Consolidate binary exponentiation files #10742
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
Conversation
""" | ||
Compute a number raised by some quantity |
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.
Why remove this? exp
is a bit cryptic in the function name and a line of documentation here is useful.
""" | ||
Compute a number raised by some quantity | ||
>>> binary_exponentiation(-1, 3) | ||
>>> binary_exp_recursive(3, 5) |
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.
What about tests for a=big number and n=big number, a=float, n=float?
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.
Can do, but the n=float case won't work because the algorithm can only compute integer powers
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 know it won’t work but I wanted to see how it fails. Does it raise a ValueError? Does it behave like pow()
does. Testing how things work if half the battle. Watching them fail is just as cool.
maths/binary_exponentiation.py
Outdated
RESULT = binary_exponentiation(BASE, POWER) | ||
print(f"{BASE}^({POWER}) : {RESULT}") | ||
RESULT = binary_exp_recursive(BASE, POWER) | ||
print(f"{BASE}^({POWER}): {RESULT}") |
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.
OPTIONAL: Adding a timeit
benchmark would be a nice addition. Visitors love to see the side-by-side bakeoff.
* Consolidate binary exponentiation files * updating DIRECTORY.md * Fix typos in doctests * Add suggestions from code review * Fix timeit benchmarks --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Describe your change:
Contributes to #8098
Consolidated implementations of binary (modular) exponentiation into just
binary_exponentiation.py
Checklist: