authorgravatar for ashe@kivikakk.eeAsherah Connor <ashe@kivikakk.ee> 2021-03-22 23:18:50+11:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-11 16:18:06+03:00
log1db6018140c20df558fc0259ae0eb28e2e08330f
treea14a47556acb6255aaf29b1fb5502197f8564fee
parent56c0a66ce30094d199420a3f2b2d2e759c1b0613

bigint: add failing tests for bigint carry


1 files changed, 26 insertions(+), 0 deletions(-)

lib/std/math/big/int_test.zig+26
...@@ -1562,3 +1562,29 @@ test "big.int pow" {...@@ -1562,3 +1562,29 @@ test "big.int pow" {
1562 try testing.expectEqual(@as(i32, 1), try a.to(i32));1562 try testing.expectEqual(@as(i32, 1), try a.to(i32));
1563 }1563 }
1564}1564}
1565
1566test "bigint regression test for 1 limb overflow with alias" {
1567 // Note these happen to be two consecutive Fibonacci sequence numbers, the
1568 // first two whose sum exceeds 2**64.
1569 var a = try Managed.initSet(testing.allocator, 7540113804746346429);
1570 defer a.deinit();
1571 var b = try Managed.initSet(testing.allocator, 12200160415121876738);
1572 defer b.deinit();
1573
1574 try a.add(a.toConst(), b.toConst());
1575
1576 try testing.expect(a.toConst().orderAgainstScalar(19740274219868223167) == .eq);
1577}
1578
1579test "bigint regression test for something else with alias" {
1580 // Note these happen to be two consecutive Fibonacci sequence numbers, the
1581 // second of which is the first such number to exceed 2**192.
1582 var a = try Managed.initSet(testing.allocator, 5611500259351924431073312796924978741056961814867751431689);
1583 defer a.deinit();
1584 var b = try Managed.initSet(testing.allocator, 9079598147510263717870894449029933369491131786514446266146);
1585 defer b.deinit();
1586
1587 try a.add(a.toConst(), b.toConst());
1588
1589 try testing.expect(a.toConst().orderAgainstScalar(14691098406862188148944207245954912110548093601382197697835) == .eq);
1590}