-
Notifications
You must be signed in to change notification settings - Fork 363
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
Added Fast Power in Number Theory #76
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
860bd1d
Added Fast Power
ahmad307 546bc5b
Updated fast Power
ahmad307 348ad07
Edited fastPower.cpp
ahmad307 60b4356
Added fastPower test file
ahmad307 e0d5338
Merge branch 'master' of https://github.com/ahmad307/Algos
ahmad307 98fd22b
Issues Fixed
ahmad307 f61dcfd
Renamed fastPower.test.cpp to FastPower.test.cpp
ahmad307 ea182d5
Duplicate removed
ahmad307 7bee107
Updated FastPower.cpp & FastPower.test.cpp
ahmad307 e90a43e
Updated FastPower.cpp
ahmad307 c4255a0
Updated FastPower.test.cpp
ahmad307 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,22 +7,22 @@ | |
|
||
TEST_CASE("Base cases", "[fast_power]") { | ||
//REQUIRE(fast_power(0,0) == undefined); | ||
REQUIRE(fast_power(0,1) == 0); | ||
REQUIRE(fast_power(1,0) == 1); | ||
REQUIRE(fast_power(1,1) == 1); | ||
REQUIRE(fast_power(0,1,ULLONG_MAX) == 0); | ||
REQUIRE(fast_power(1,0,ULLONG_MAX) == 1); | ||
REQUIRE(fast_power(1,1,ULLONG_MAX) == 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! Sorry for this. |
||
} | ||
|
||
TEST_CASE("Normal cases", "[fast_power]") { | ||
REQUIRE(fast_power(2,2) == 4); | ||
REQUIRE(fast_power(2,4) == 16); | ||
REQUIRE(fast_power(3,4) == 81); | ||
REQUIRE(fast_power(7,9) == 40353607); | ||
REQUIRE(fast_power(15,10) == 576650390625); | ||
REQUIRE(fast_power(2,2,ULLONG_MAX) == 4); | ||
REQUIRE(fast_power(2,4,ULLONG_MAX) == 16); | ||
REQUIRE(fast_power(3,4,ULLONG_MAX) == 81); | ||
REQUIRE(fast_power(7,9,ULLONG_MAX) == 40353607); | ||
REQUIRE(fast_power(15,10,ULLONG_MAX) == 576650390625); | ||
} | ||
|
||
TEST_CASE("Overflow cases", "[fast_power]") { | ||
REQUIRE(fast_power(2,100) == 68719476736); | ||
REQUIRE(fast_power(10,99) == 4440381706574496940U); | ||
REQUIRE(fast_power(2,100,1000000007) == 976371285); | ||
REQUIRE(fast_power(10,99,1000000007) == 22673271); | ||
} | ||
|
||
#undef FAST_POWER_TEST |
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.
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.
Give
mod
the default valueULLONG_MAX
so that it doesn't need to be passed to the function if modulus of the result is not required.