-
Notifications
You must be signed in to change notification settings - Fork 131
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
GCD implementation using Euclid's algorithm #14
Conversation
Codecov Report
@@ Coverage Diff @@
## master #14 +/- ##
==========================================
- Coverage 98.94% 95.14% -3.81%
==========================================
Files 12 12
Lines 475 494 +19
==========================================
Hits 470 470
- Misses 5 24 +19
Continue to review full report at Codecov.
|
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.
Please also add unit tests for gcd()
in test/functions/math.test.cpp
.
// gcd: | ||
friend BigInt gcd(const BigInt& num1, const BigInt& num2); | ||
friend BigInt gcd(const BigInt& num1, const long long& num2); | ||
friend BigInt gcd(const BigInt& num1, const std::string& num2); |
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.
The GCD functions don't need to be friends of BigInt as they can be implemented without accessing the private members.
|
||
// Trivial Case handling | ||
if(abs_num1.value == "0") return abs_num2; | ||
else if (abs_num2.value == "0") return abs_num1; |
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.
You can do:
if (abs_num1 == 0)
return abs_num2;
if (abs_num2 == 0)
return abs_num1;
@anandsit043 You have made changes directly to your |
Follow up in #15. |
Modified files : BigInt.hpp and operators/binary_arithmetic.hpp
Please review