mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
std::math::bigint: Fixed init_with_array with empty array
This commit is contained in:
committed by
Christoffer Lerno
parent
38110b0269
commit
ed62268997
@@ -63,6 +63,13 @@ fn BigInt* BigInt.init_with_u128(&self, uint128 value)
|
||||
fn BigInt* BigInt.init_with_array(&self, uint[] values)
|
||||
{
|
||||
self.data[..] = 0;
|
||||
|
||||
if (values.len == 0)
|
||||
{
|
||||
self.len = 1;
|
||||
return self;
|
||||
}
|
||||
|
||||
self.len = values.len;
|
||||
|
||||
foreach_r(i, val : values)
|
||||
|
||||
@@ -9,9 +9,8 @@ fn void test_init_with_u128()
|
||||
fn void init_with_array()
|
||||
{
|
||||
BigInt bi @noinit;
|
||||
|
||||
assert(bi.init_with_array({}).equals(ZERO));
|
||||
assert(bi.init_with_array({0, 0, 0, 1}).equals(bigint::from_int(1)));
|
||||
|
||||
assert("100000000" == bi.init_with_array({1, 0}).to_string_with_radix(16, allocator::temp()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user