generated from eigerco/beerus
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!--- Please provide a general summary of your changes in the title above --> Updating the `pow` impl to use binary exponentiation, which is cheaper. <!-- Please try to limit your pull request to one type; submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [ ] Bugfix - [x] Feature - [ ] Code style update (formatting, renaming) - [x] Refactoring (no functional changes, no API changes) - [ ] Build-related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? `pow` is O(n) ## What is the new behavior? `pow` is O(log n) ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this does introduce a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information I did a simple [benchmark](https://gist.github.com/milancermak/adf6c70cdd550155a754e335d92fcbf5). Stepwise performance is the same for a simple case, the greater the exponent the more efficient this new implementation is. Added a testcase to check for the whole 2^N range. FWIW, it's pretty much the same as `BitShift::fpow` 😁 but without the use of Bitwise ops.
- Loading branch information
1 parent
a3052ff
commit e863e5b
Showing
2 changed files
with
145 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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