-
Notifications
You must be signed in to change notification settings - Fork 26
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
Feat: Multiply Operator (*) overload with tests #59
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f6468c8
Added * operator
HashirGJ8842 7b17cf7
Added simple multiplication
HashirGJ8842 cad856c
Added Karatsuba Algorithm
HashirGJ8842 85e20c5
Added tests
HashirGJ8842 b266e6f
Update
HashirGJ8842 ea72ea6
Resolved Codacy Issues
HashirGJ8842 3bb3e79
Reolved issues
HashirGJ8842 982a48b
Fixed bugs
HashirGJ8842 c83cbd8
Added more tests
HashirGJ8842 dfb58f4
Resolved issues
HashirGJ8842 d2118aa
Update
HashirGJ8842 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Boost Software License - Version 1.0 - August 17th, 2003 | ||
* Permission is hereby granted, free of charge, to any person | ||
* or organization obtaining a copy of the software and | ||
* accompanying documentation covered by this license | ||
* (the "Software") to use, reproduce, display, distribute, | ||
* execute, and transmit the Software, and to prepare derivative | ||
* works of the Software, and to permit third-parties to whom the | ||
* Software is furnished to do so, all subject to the following: | ||
* | ||
* The copyright notices in the Software and this entire statement, | ||
* including the above license grant, this restriction and the following | ||
* disclaimer, must be included in all copies of the Software, in whole or | ||
* in part, and all derivative works of the Software, unless such copies | ||
* or derivative works are solely in the form of machine-executable | ||
* object code generated by a source language processor. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND | ||
* NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE | ||
* DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
#include <istream> | ||
#include <ostream> | ||
#include <bigint.hpp> | ||
#include <algorithm> | ||
|
||
namespace libbig | ||
{ | ||
int char_int_converter(const char &x) { | ||
return ((x >= '0' && x <= '9') ? x - '0' : x + '0') ; | ||
} | ||
} // namespace libbig |
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
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <bigint.hpp> | ||
#include <iostream> | ||
#include <cassert> | ||
|
||
int main() | ||
{ | ||
/// Tests for multiplication of largeInt to largeInt (largeInt * largeInt) | ||
/// Test 1 | ||
libbig::largeInt a("1"); | ||
libbig::largeInt b("1"); | ||
libbig::largeInt c = a * b; | ||
assert(c == libbig::largeInt("1")); | ||
|
||
/// Test 2 | ||
a = libbig::largeInt("999"); | ||
b = libbig::largeInt("99999"); | ||
c = a * b; | ||
assert(c == libbig::largeInt("99899001")); | ||
|
||
/// Test 3 | ||
a = libbig::largeInt("32516889472103571029388908423975"); | ||
b = libbig::largeInt("0"); | ||
c = a * b; | ||
assert(c == libbig::largeInt("0")); | ||
|
||
/// Test 4 | ||
a = libbig::largeInt("6666666666666"); | ||
b = libbig::largeInt("58723619378"); | ||
c = a * b; | ||
assert(c == libbig::largeInt("391490795853294184253748")); | ||
|
||
// Test 5 | ||
a = libbig::largeInt("33"); | ||
b = libbig::largeInt("-2"); | ||
c = a * b; | ||
assert(c == libbig::largeInt("-66")); | ||
|
||
// Test 6 | ||
a = libbig::largeInt("78239823648904375"); | ||
b = libbig::largeInt("1273898653482713986555"); | ||
c = a * b; | ||
assert(c == libbig::largeInt("99669605995064285419229672514230678125")); | ||
|
||
// Test 7 | ||
a = libbig::largeInt("-0"); | ||
b = libbig::largeInt("100"); | ||
c = a * b; | ||
assert(c == libbig::largeInt("0")); | ||
|
||
// Test 8 | ||
a = libbig::largeInt("-100"); | ||
b = libbig::largeInt("-100"); | ||
c = a * b; | ||
assert(c == libbig::largeInt("10000")); | ||
|
||
// Test 9 | ||
a = libbig::largeInt("0000000000000000000000000000000000000000000000000000"); | ||
b = libbig::largeInt("1111111111111111111111111111111111111111111111111111"); | ||
c = a * b; | ||
assert(c == libbig::largeInt("0")); | ||
|
||
// Test 10 | ||
a = libbig::largeInt("746767836578647567834567834657836587"); | ||
b = libbig::largeInt("89275924758922476024759846938475804579247593468034769835763597028476937"); | ||
c = a * b; | ||
assert(c == libbig::largeInt("66668389190778655840704160824409791548824154145813767587653936294222881640592188804856387839101068044294019")); | ||
|
||
// Test 10 | ||
a = libbig::largeInt("8492387957349593498354782359782345782367895623478567894235692347856789234789236789342967891235627348589234567892345234567892369287345"); | ||
b = libbig::largeInt("824358293475908745902350926589023459023485089347892650234650273456207349236502347524357832456789235623489759235623789456782394567892359478235239423569782356234659837562378965278956237489235"); | ||
c = a * b; | ||
assert(c == libbig::largeInt("7000770444056069403046119404826740387252166452093943636486324185225836788920060077258109995450330997820727632474615791121779806923541276193853962113432983583426568371447855101334504301369704676060587738461922443343618487980096828486083202559107333726983966552151422667448209619250487990929538296732965889159956209059231075")); | ||
|
||
ayaankhan98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return 0; | ||
} |
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.
still two overloads are missing.
for
largeInt * int
andlargeInt * int64_t
(int64_t
akalong long
)