diff --git a/lib/std/math/bigint.c3 b/lib/std/math/bigint.c3 index 5fb303099..79462a27d 100644 --- a/lib/std/math/bigint.c3 +++ b/lib/std/math/bigint.c3 @@ -35,7 +35,7 @@ fn BigInt* BigInt.init(&self, int128 value) len++; } assert(value < 0 || tmp == 0 || !self.is_negative()); - assert(value > 0 || tmp == -1 || self.is_negative()); + assert(value >= 0 || tmp == -1 || self.is_negative()); self.len = len; self.reduce_len(); return self; diff --git a/releasenotes.md b/releasenotes.md index 07e5dada3..a104edf7f 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -50,6 +50,7 @@ - Issue with defer copying when triggered by break or continue #1936. - Assert when using optional as init or inc part in a for loop #1942. - Fix bigint hex parsing #1945. +- `bigint::from_int(0)` throws assertion #1944. ### Stdlib changes - Added '%h' and '%H' for printing out binary data in hexadecimal using the formatter. diff --git a/test/unit/stdlib/math/bigint.c3 b/test/unit/stdlib/math/bigint.c3 index db99ae935..41b21f718 100644 --- a/test/unit/stdlib/math/bigint.c3 +++ b/test/unit/stdlib/math/bigint.c3 @@ -6,6 +6,14 @@ fn void test_parse16() assert(bi.init_string_radix("c", 16)!!.equals(bigint::from_int(12))); } +fn void test_zero() +{ + assert(bigint::from_int(0).to_string(allocator::temp()) == "0"); + BigInt bi; + bi.init_string_radix("00", 16)!!; + assert(bi.to_string(allocator::temp()) == "0"); +} + fn void test_plus() { BigInt a = bigint::from_int(123);