-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
BigInt: reallocate space, digit_t, increment, decrement #5788
Merged
chakrabot
merged 1 commit into
chakra-core:master
from
duongnhn:user/duongn/bigint_size_t
Oct 23, 2018
Merged
Changes from all commits
Commits
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,84 @@ | ||
//------------------------------------------------------------------------------------------------------- | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
//------------------------------------------------------------------------------------------------------- | ||
|
||
#include "stdafx.h" | ||
#pragma warning(disable:26434) // Function definition hides non-virtual function in base class | ||
#pragma warning(disable:26439) // Implicit noexcept | ||
#pragma warning(disable:26451) // Arithmetic overflow | ||
#pragma warning(disable:26495) // Uninitialized member variable | ||
#include "catch.hpp" | ||
|
||
#pragma warning(disable:4100) // unreferenced formal parameter | ||
#pragma warning(disable:6387) // suppressing preFAST which raises warning for passing null to the JsRT APIs | ||
#pragma warning(disable:6262) // CATCH is using stack variables to report errors, suppressing the preFAST warning. | ||
|
||
namespace JavascriptBigIntTests | ||
{ | ||
void Test_AddDigit(digit_t digit1, digit_t digit2, digit_t * carry, digit_t expectedResult, digit_t expectedCarry) | ||
{ | ||
REQUIRE(g_testHooksLoaded); | ||
|
||
digit_t res = g_testHooks.pfAddDigit(digit1, digit2, carry); | ||
|
||
//test to check that the result from call to AddDigit is the expected value | ||
REQUIRE(res == expectedResult); | ||
REQUIRE(expectedCarry == *carry); | ||
} | ||
|
||
void Test_SubDigit(digit_t digit1, digit_t digit2, digit_t * borrow, digit_t expectedResult, digit_t expectedBorrow) | ||
{ | ||
REQUIRE(g_testHooksLoaded); | ||
|
||
digit_t res = g_testHooks.pfSubDigit(digit1, digit2, borrow); | ||
|
||
//test to check that the result from call to SubtractDigit is the expected value | ||
REQUIRE(res == expectedResult); | ||
REQUIRE(*borrow == expectedBorrow); | ||
} | ||
|
||
void Test_MulDigit(digit_t digit1, digit_t digit2, digit_t * high, digit_t expectedResult, digit_t expectedHigh) | ||
{ | ||
REQUIRE(g_testHooksLoaded); | ||
|
||
digit_t res = g_testHooks.pfMulDigit(digit1, digit2, high); | ||
|
||
//test to check that the result from call to SubtractDigit is the expected value | ||
REQUIRE(res == expectedResult); | ||
REQUIRE(*high == expectedHigh); | ||
} | ||
|
||
TEST_CASE("AddDigit", "[JavascriptBigIntTests]") | ||
{ | ||
digit_t carry = 0; | ||
Test_AddDigit(1, 2, &carry, 3, 0); | ||
|
||
digit_t d1 = UINTPTR_MAX; | ||
digit_t d2 = UINTPTR_MAX; | ||
carry = 0; | ||
Test_AddDigit(d1, d2, &carry, UINTPTR_MAX-1, 1); | ||
} | ||
|
||
TEST_CASE("SubDigit", "[JavascriptBigIntTests]") | ||
{ | ||
digit_t borrow = 0; | ||
Test_SubDigit(3, 2, &borrow, 1, 0); | ||
|
||
digit_t d1 = 0; | ||
digit_t d2 = 1; | ||
borrow = 0; | ||
Test_SubDigit(d1, d2, &borrow, UINTPTR_MAX, 1); | ||
} | ||
|
||
TEST_CASE("MulDigit", "[JavascriptBigIntTests]") | ||
{ | ||
digit_t high = 0; | ||
Test_MulDigit(3, 2, &high, 6, 0); | ||
|
||
digit_t d1 = UINTPTR_MAX; | ||
digit_t d2 = 2; | ||
high = 0; | ||
Test_MulDigit(d1, d2, &high, UINTPTR_MAX-1, 1); | ||
} | ||
} |
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
Oops, something went wrong.
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.
define a digit of BigInt