-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Optimize BigInt→decimal in IntegerToString #123580
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
Changes from 1 commit
b9168b8
dc831a9
54270bc
b80067d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
#include "test/UnitTest/Test.h" | ||
|
||
using LIBC_NAMESPACE::BigInt; | ||
using LIBC_NAMESPACE::IntegerToString; | ||
using LIBC_NAMESPACE::cpp::span; | ||
using LIBC_NAMESPACE::cpp::string_view; | ||
|
@@ -297,6 +298,51 @@ TEST(LlvmLibcIntegerToStringTest, Sign) { | |
EXPECT(DEC, 1, "+1"); | ||
} | ||
|
||
TEST(LlvmLibcIntegerToStringTest, BigInt_Base_10) { | ||
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. Do you mind adding some tests for 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. Done. The extra tests look a bit repetitive – half of me wanted to try to template them and call the template three times with different types, or something. But perhaps it's better this way because if one (ever) fails then the line number will make it clear which. 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. Thanks! And maybe they won't have to be touched too much in the future. |
||
uint64_t uint256_max[4] = { | ||
0xFFFFFFFFFFFFFFFF, | ||
0xFFFFFFFFFFFFFFFF, | ||
0xFFFFFFFFFFFFFFFF, | ||
0xFFFFFFFFFFFFFFFF, | ||
}; | ||
uint64_t int256_max[4] = { | ||
0xFFFFFFFFFFFFFFFF, | ||
0xFFFFFFFFFFFFFFFF, | ||
0xFFFFFFFFFFFFFFFF, | ||
0x7FFFFFFFFFFFFFFF, | ||
}; | ||
uint64_t int256_min[4] = { | ||
0, | ||
0, | ||
0, | ||
0x8000000000000000, | ||
}; | ||
|
||
using unsigned_type = IntegerToString<BigInt<256, false>, Dec>; | ||
EXPECT(unsigned_type, 0, "0"); | ||
EXPECT(unsigned_type, 1, "1"); | ||
EXPECT(unsigned_type, uint256_max, | ||
"115792089237316195423570985008687907853269984665640564039457584007913" | ||
"129639935"); | ||
EXPECT(unsigned_type, int256_max, | ||
"578960446186580977117854925043439539266349923328202820197287920039565" | ||
"64819967"); | ||
EXPECT(unsigned_type, int256_min, | ||
"578960446186580977117854925043439539266349923328202820197287920039565" | ||
"64819968"); | ||
|
||
using signed_type = IntegerToString<BigInt<256, true>, Dec>; | ||
EXPECT(signed_type, 0, "0"); | ||
EXPECT(signed_type, 1, "1"); | ||
EXPECT(signed_type, uint256_max, "-1"); | ||
EXPECT(signed_type, int256_max, | ||
"578960446186580977117854925043439539266349923328202820197287920039565" | ||
"64819967"); | ||
EXPECT(signed_type, int256_min, | ||
"-57896044618658097711785492504343953926634992332820282019728792003956" | ||
"564819968"); | ||
} | ||
|
||
TEST(LlvmLibcIntegerToStringTest, BufferOverrun) { | ||
{ // Writing '0' in an empty buffer requiring zero digits : works | ||
const auto view = | ||
|
Uh oh!
There was an error while loading. Please reload this page.