| ... | ... | @@ -166,7 +166,7 @@ test "big.int bitcount + sizeInBaseUpperBound" { |
| 166 | 166 | try testing.expect(a.sizeInBaseUpperBound(2) >= 32); |
| 167 | 167 | try testing.expect(a.sizeInBaseUpperBound(10) >= 10); |
| 168 | 168 | |
| 169 | | try a.shiftLeft(a, 5000); |
| 169 | try a.shiftLeft(&a, 5000); |
| 170 | 170 | try testing.expect(a.bitCountAbs() == 5032); |
| 171 | 171 | try testing.expect(a.sizeInBaseUpperBound(2) >= 5032); |
| 172 | 172 | a.setSign(false); |
| ... | ... | @@ -486,7 +486,7 @@ test "big.int add single-single" { |
| 486 | 486 | |
| 487 | 487 | var c = try Managed.init(testing.allocator); |
| 488 | 488 | defer c.deinit(); |
| 489 | | try c.add(a.toConst(), b.toConst()); |
| 489 | try c.add(&a, &b); |
| 490 | 490 | |
| 491 | 491 | try testing.expect((try c.to(u32)) == 55); |
| 492 | 492 | } |
| ... | ... | @@ -500,10 +500,10 @@ test "big.int add multi-single" { |
| 500 | 500 | var c = try Managed.init(testing.allocator); |
| 501 | 501 | defer c.deinit(); |
| 502 | 502 | |
| 503 | | try c.add(a.toConst(), b.toConst()); |
| 503 | try c.add(&a, &b); |
| 504 | 504 | try testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2); |
| 505 | 505 | |
| 506 | | try c.add(b.toConst(), a.toConst()); |
| 506 | try c.add(&b, &a); |
| 507 | 507 | try testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2); |
| 508 | 508 | } |
| 509 | 509 | |
| ... | ... | @@ -517,7 +517,7 @@ test "big.int add multi-multi" { |
| 517 | 517 | |
| 518 | 518 | var c = try Managed.init(testing.allocator); |
| 519 | 519 | defer c.deinit(); |
| 520 | | try c.add(a.toConst(), b.toConst()); |
| 520 | try c.add(&a, &b); |
| 521 | 521 | |
| 522 | 522 | try testing.expect((try c.to(u128)) == op1 + op2); |
| 523 | 523 | } |
| ... | ... | @@ -530,7 +530,7 @@ test "big.int add zero-zero" { |
| 530 | 530 | |
| 531 | 531 | var c = try Managed.init(testing.allocator); |
| 532 | 532 | defer c.deinit(); |
| 533 | | try c.add(a.toConst(), b.toConst()); |
| 533 | try c.add(&a, &b); |
| 534 | 534 | |
| 535 | 535 | try testing.expect((try c.to(u32)) == 0); |
| 536 | 536 | } |
| ... | ... | @@ -542,7 +542,7 @@ test "big.int add alias multi-limb nonzero-zero" { |
| 542 | 542 | var b = try Managed.initSet(testing.allocator, 0); |
| 543 | 543 | defer b.deinit(); |
| 544 | 544 | |
| 545 | | try a.add(a.toConst(), b.toConst()); |
| 545 | try a.add(&a, &b); |
| 546 | 546 | |
| 547 | 547 | try testing.expect((try a.to(u128)) == op1); |
| 548 | 548 | } |
| ... | ... | @@ -560,16 +560,16 @@ test "big.int add sign" { |
| 560 | 560 | var neg_two = try Managed.initSet(testing.allocator, -2); |
| 561 | 561 | defer neg_two.deinit(); |
| 562 | 562 | |
| 563 | | try a.add(one.toConst(), two.toConst()); |
| 563 | try a.add(&one, &two); |
| 564 | 564 | try testing.expect((try a.to(i32)) == 3); |
| 565 | 565 | |
| 566 | | try a.add(neg_one.toConst(), two.toConst()); |
| 566 | try a.add(&neg_one, &two); |
| 567 | 567 | try testing.expect((try a.to(i32)) == 1); |
| 568 | 568 | |
| 569 | | try a.add(one.toConst(), neg_two.toConst()); |
| 569 | try a.add(&one, &neg_two); |
| 570 | 570 | try testing.expect((try a.to(i32)) == -1); |
| 571 | 571 | |
| 572 | | try a.add(neg_one.toConst(), neg_two.toConst()); |
| 572 | try a.add(&neg_one, &neg_two); |
| 573 | 573 | try testing.expect((try a.to(i32)) == -3); |
| 574 | 574 | } |
| 575 | 575 | |
| ... | ... | @@ -579,7 +579,7 @@ test "big.int add scalar" { |
| 579 | 579 | |
| 580 | 580 | var b = try Managed.init(testing.allocator); |
| 581 | 581 | defer b.deinit(); |
| 582 | | try b.addScalar(a.toConst(), 5); |
| 582 | try b.addScalar(&a, 5); |
| 583 | 583 | |
| 584 | 584 | try testing.expect((try b.to(u32)) == 55); |
| 585 | 585 | } |
| ... | ... | @@ -591,7 +591,7 @@ test "big.int addWrap single-single, unsigned" { |
| 591 | 591 | var b = try Managed.initSet(testing.allocator, 10); |
| 592 | 592 | defer b.deinit(); |
| 593 | 593 | |
| 594 | | const wrapped = try a.addWrap(a.toConst(), b.toConst(), .unsigned, 17); |
| 594 | const wrapped = try a.addWrap(&a, &b, .unsigned, 17); |
| 595 | 595 | |
| 596 | 596 | try testing.expect(wrapped); |
| 597 | 597 | try testing.expect((try a.to(u17)) == 9); |
| ... | ... | @@ -604,7 +604,7 @@ test "big.int subWrap single-single, unsigned" { |
| 604 | 604 | var b = try Managed.initSet(testing.allocator, maxInt(u17)); |
| 605 | 605 | defer b.deinit(); |
| 606 | 606 | |
| 607 | | const wrapped = try a.subWrap(a.toConst(), b.toConst(), .unsigned, 17); |
| 607 | const wrapped = try a.subWrap(&a, &b, .unsigned, 17); |
| 608 | 608 | |
| 609 | 609 | try testing.expect(wrapped); |
| 610 | 610 | try testing.expect((try a.to(u17)) == 1); |
| ... | ... | @@ -617,7 +617,7 @@ test "big.int addWrap multi-multi, unsigned, limb aligned" { |
| 617 | 617 | var b = try Managed.initSet(testing.allocator, maxInt(DoubleLimb)); |
| 618 | 618 | defer b.deinit(); |
| 619 | 619 | |
| 620 | | const wrapped = try a.addWrap(a.toConst(), b.toConst(), .unsigned, @bitSizeOf(DoubleLimb)); |
| 620 | const wrapped = try a.addWrap(&a, &b, .unsigned, @bitSizeOf(DoubleLimb)); |
| 621 | 621 | |
| 622 | 622 | try testing.expect(wrapped); |
| 623 | 623 | try testing.expect((try a.to(DoubleLimb)) == maxInt(DoubleLimb) - 1); |
| ... | ... | @@ -630,7 +630,7 @@ test "big.int subWrap single-multi, unsigned, limb aligned" { |
| 630 | 630 | var b = try Managed.initSet(testing.allocator, maxInt(DoubleLimb) + 100); |
| 631 | 631 | defer b.deinit(); |
| 632 | 632 | |
| 633 | | const wrapped = try a.subWrap(a.toConst(), b.toConst(), .unsigned, @bitSizeOf(DoubleLimb)); |
| 633 | const wrapped = try a.subWrap(&a, &b, .unsigned, @bitSizeOf(DoubleLimb)); |
| 634 | 634 | |
| 635 | 635 | try testing.expect(wrapped); |
| 636 | 636 | try testing.expect((try a.to(DoubleLimb)) == maxInt(DoubleLimb) - 88); |
| ... | ... | @@ -643,7 +643,7 @@ test "big.int addWrap single-single, signed" { |
| 643 | 643 | var b = try Managed.initSet(testing.allocator, 1 + 1 + maxInt(u21)); |
| 644 | 644 | defer b.deinit(); |
| 645 | 645 | |
| 646 | | const wrapped = try a.addWrap(a.toConst(), b.toConst(), .signed, @bitSizeOf(i21)); |
| 646 | const wrapped = try a.addWrap(&a, &b, .signed, @bitSizeOf(i21)); |
| 647 | 647 | |
| 648 | 648 | try testing.expect(wrapped); |
| 649 | 649 | try testing.expect((try a.to(i21)) == minInt(i21)); |
| ... | ... | @@ -656,7 +656,7 @@ test "big.int subWrap single-single, signed" { |
| 656 | 656 | var b = try Managed.initSet(testing.allocator, 1); |
| 657 | 657 | defer b.deinit(); |
| 658 | 658 | |
| 659 | | const wrapped = try a.subWrap(a.toConst(), b.toConst(), .signed, @bitSizeOf(i21)); |
| 659 | const wrapped = try a.subWrap(&a, &b, .signed, @bitSizeOf(i21)); |
| 660 | 660 | |
| 661 | 661 | try testing.expect(wrapped); |
| 662 | 662 | try testing.expect((try a.to(i21)) == maxInt(i21)); |
| ... | ... | @@ -669,7 +669,7 @@ test "big.int addWrap multi-multi, signed, limb aligned" { |
| 669 | 669 | var b = try Managed.initSet(testing.allocator, maxInt(SignedDoubleLimb)); |
| 670 | 670 | defer b.deinit(); |
| 671 | 671 | |
| 672 | | const wrapped = try a.addWrap(a.toConst(), b.toConst(), .signed, @bitSizeOf(SignedDoubleLimb)); |
| 672 | const wrapped = try a.addWrap(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb)); |
| 673 | 673 | |
| 674 | 674 | try testing.expect(wrapped); |
| 675 | 675 | try testing.expect((try a.to(SignedDoubleLimb)) == -2); |
| ... | ... | @@ -682,7 +682,7 @@ test "big.int subWrap single-multi, signed, limb aligned" { |
| 682 | 682 | var b = try Managed.initSet(testing.allocator, 1); |
| 683 | 683 | defer b.deinit(); |
| 684 | 684 | |
| 685 | | const wrapped = try a.subWrap(a.toConst(), b.toConst(), .signed, @bitSizeOf(SignedDoubleLimb)); |
| 685 | const wrapped = try a.subWrap(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb)); |
| 686 | 686 | |
| 687 | 687 | try testing.expect(wrapped); |
| 688 | 688 | try testing.expect((try a.to(SignedDoubleLimb)) == maxInt(SignedDoubleLimb)); |
| ... | ... | @@ -695,7 +695,7 @@ test "big.int addSat single-single, unsigned" { |
| 695 | 695 | var b = try Managed.initSet(testing.allocator, 10); |
| 696 | 696 | defer b.deinit(); |
| 697 | 697 | |
| 698 | | try a.addSat(a.toConst(), b.toConst(), .unsigned, 17); |
| 698 | try a.addSat(&a, &b, .unsigned, 17); |
| 699 | 699 | |
| 700 | 700 | try testing.expect((try a.to(u17)) == maxInt(u17)); |
| 701 | 701 | } |
| ... | ... | @@ -707,7 +707,7 @@ test "big.int subSat single-single, unsigned" { |
| 707 | 707 | var b = try Managed.initSet(testing.allocator, 4000); |
| 708 | 708 | defer b.deinit(); |
| 709 | 709 | |
| 710 | | try a.subSat(a.toConst(), b.toConst(), .unsigned, 17); |
| 710 | try a.subSat(&a, &b, .unsigned, 17); |
| 711 | 711 | |
| 712 | 712 | try testing.expect((try a.to(u17)) == 0); |
| 713 | 713 | } |
| ... | ... | @@ -719,7 +719,7 @@ test "big.int addSat multi-multi, unsigned, limb aligned" { |
| 719 | 719 | var b = try Managed.initSet(testing.allocator, maxInt(DoubleLimb)); |
| 720 | 720 | defer b.deinit(); |
| 721 | 721 | |
| 722 | | try a.addSat(a.toConst(), b.toConst(), .unsigned, @bitSizeOf(DoubleLimb)); |
| 722 | try a.addSat(&a, &b, .unsigned, @bitSizeOf(DoubleLimb)); |
| 723 | 723 | |
| 724 | 724 | try testing.expect((try a.to(DoubleLimb)) == maxInt(DoubleLimb)); |
| 725 | 725 | } |
| ... | ... | @@ -731,7 +731,7 @@ test "big.int subSat single-multi, unsigned, limb aligned" { |
| 731 | 731 | var b = try Managed.initSet(testing.allocator, maxInt(DoubleLimb) + 100); |
| 732 | 732 | defer b.deinit(); |
| 733 | 733 | |
| 734 | | try a.subSat(a.toConst(), b.toConst(), .unsigned, @bitSizeOf(DoubleLimb)); |
| 734 | try a.subSat(&a, &b, .unsigned, @bitSizeOf(DoubleLimb)); |
| 735 | 735 | |
| 736 | 736 | try testing.expect((try a.to(DoubleLimb)) == 0); |
| 737 | 737 | } |
| ... | ... | @@ -743,7 +743,7 @@ test "big.int addSat single-single, signed" { |
| 743 | 743 | var b = try Managed.initSet(testing.allocator, 1); |
| 744 | 744 | defer b.deinit(); |
| 745 | 745 | |
| 746 | | try a.addSat(a.toConst(), b.toConst(), .signed, @bitSizeOf(i14)); |
| 746 | try a.addSat(&a, &b, .signed, @bitSizeOf(i14)); |
| 747 | 747 | |
| 748 | 748 | try testing.expect((try a.to(i14)) == maxInt(i14)); |
| 749 | 749 | } |
| ... | ... | @@ -755,7 +755,7 @@ test "big.int subSat single-single, signed" { |
| 755 | 755 | var b = try Managed.initSet(testing.allocator, 1); |
| 756 | 756 | defer b.deinit(); |
| 757 | 757 | |
| 758 | | try a.subSat(a.toConst(), b.toConst(), .signed, @bitSizeOf(i21)); |
| 758 | try a.subSat(&a, &b, .signed, @bitSizeOf(i21)); |
| 759 | 759 | |
| 760 | 760 | try testing.expect((try a.to(i21)) == minInt(i21)); |
| 761 | 761 | } |
| ... | ... | @@ -767,7 +767,7 @@ test "big.int addSat multi-multi, signed, limb aligned" { |
| 767 | 767 | var b = try Managed.initSet(testing.allocator, maxInt(SignedDoubleLimb)); |
| 768 | 768 | defer b.deinit(); |
| 769 | 769 | |
| 770 | | try a.addSat(a.toConst(), b.toConst(), .signed, @bitSizeOf(SignedDoubleLimb)); |
| 770 | try a.addSat(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb)); |
| 771 | 771 | |
| 772 | 772 | try testing.expect((try a.to(SignedDoubleLimb)) == maxInt(SignedDoubleLimb)); |
| 773 | 773 | } |
| ... | ... | @@ -779,7 +779,7 @@ test "big.int subSat single-multi, signed, limb aligned" { |
| 779 | 779 | var b = try Managed.initSet(testing.allocator, 1); |
| 780 | 780 | defer b.deinit(); |
| 781 | 781 | |
| 782 | | try a.subSat(a.toConst(), b.toConst(), .signed, @bitSizeOf(SignedDoubleLimb)); |
| 782 | try a.subSat(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb)); |
| 783 | 783 | |
| 784 | 784 | try testing.expect((try a.to(SignedDoubleLimb)) == minInt(SignedDoubleLimb)); |
| 785 | 785 | } |
| ... | ... | @@ -792,7 +792,7 @@ test "big.int sub single-single" { |
| 792 | 792 | |
| 793 | 793 | var c = try Managed.init(testing.allocator); |
| 794 | 794 | defer c.deinit(); |
| 795 | | try c.sub(a.toConst(), b.toConst()); |
| 795 | try c.sub(&a, &b); |
| 796 | 796 | |
| 797 | 797 | try testing.expect((try c.to(u32)) == 45); |
| 798 | 798 | } |
| ... | ... | @@ -805,7 +805,7 @@ test "big.int sub multi-single" { |
| 805 | 805 | |
| 806 | 806 | var c = try Managed.init(testing.allocator); |
| 807 | 807 | defer c.deinit(); |
| 808 | | try c.sub(a.toConst(), b.toConst()); |
| 808 | try c.sub(&a, &b); |
| 809 | 809 | |
| 810 | 810 | try testing.expect((try c.to(Limb)) == maxInt(Limb)); |
| 811 | 811 | } |
| ... | ... | @@ -821,7 +821,7 @@ test "big.int sub multi-multi" { |
| 821 | 821 | |
| 822 | 822 | var c = try Managed.init(testing.allocator); |
| 823 | 823 | defer c.deinit(); |
| 824 | | try c.sub(a.toConst(), b.toConst()); |
| 824 | try c.sub(&a, &b); |
| 825 | 825 | |
| 826 | 826 | try testing.expect((try c.to(u128)) == op1 - op2); |
| 827 | 827 | } |
| ... | ... | @@ -834,7 +834,7 @@ test "big.int sub equal" { |
| 834 | 834 | |
| 835 | 835 | var c = try Managed.init(testing.allocator); |
| 836 | 836 | defer c.deinit(); |
| 837 | | try c.sub(a.toConst(), b.toConst()); |
| 837 | try c.sub(&a, &b); |
| 838 | 838 | |
| 839 | 839 | try testing.expect((try c.to(u32)) == 0); |
| 840 | 840 | } |
| ... | ... | @@ -852,19 +852,19 @@ test "big.int sub sign" { |
| 852 | 852 | var neg_two = try Managed.initSet(testing.allocator, -2); |
| 853 | 853 | defer neg_two.deinit(); |
| 854 | 854 | |
| 855 | | try a.sub(one.toConst(), two.toConst()); |
| 855 | try a.sub(&one, &two); |
| 856 | 856 | try testing.expect((try a.to(i32)) == -1); |
| 857 | 857 | |
| 858 | | try a.sub(neg_one.toConst(), two.toConst()); |
| 858 | try a.sub(&neg_one, &two); |
| 859 | 859 | try testing.expect((try a.to(i32)) == -3); |
| 860 | 860 | |
| 861 | | try a.sub(one.toConst(), neg_two.toConst()); |
| 861 | try a.sub(&one, &neg_two); |
| 862 | 862 | try testing.expect((try a.to(i32)) == 3); |
| 863 | 863 | |
| 864 | | try a.sub(neg_one.toConst(), neg_two.toConst()); |
| 864 | try a.sub(&neg_one, &neg_two); |
| 865 | 865 | try testing.expect((try a.to(i32)) == 1); |
| 866 | 866 | |
| 867 | | try a.sub(neg_two.toConst(), neg_one.toConst()); |
| 867 | try a.sub(&neg_two, &neg_one); |
| 868 | 868 | try testing.expect((try a.to(i32)) == -1); |
| 869 | 869 | } |
| 870 | 870 | |
| ... | ... | @@ -876,7 +876,7 @@ test "big.int mul single-single" { |
| 876 | 876 | |
| 877 | 877 | var c = try Managed.init(testing.allocator); |
| 878 | 878 | defer c.deinit(); |
| 879 | | try c.mul(a.toConst(), b.toConst()); |
| 879 | try c.mul(&a, &b); |
| 880 | 880 | |
| 881 | 881 | try testing.expect((try c.to(u64)) == 250); |
| 882 | 882 | } |
| ... | ... | @@ -889,7 +889,7 @@ test "big.int mul multi-single" { |
| 889 | 889 | |
| 890 | 890 | var c = try Managed.init(testing.allocator); |
| 891 | 891 | defer c.deinit(); |
| 892 | | try c.mul(a.toConst(), b.toConst()); |
| 892 | try c.mul(&a, &b); |
| 893 | 893 | |
| 894 | 894 | try testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb)); |
| 895 | 895 | } |
| ... | ... | @@ -904,7 +904,7 @@ test "big.int mul multi-multi" { |
| 904 | 904 | |
| 905 | 905 | var c = try Managed.init(testing.allocator); |
| 906 | 906 | defer c.deinit(); |
| 907 | | try c.mul(a.toConst(), b.toConst()); |
| 907 | try c.mul(&a, &b); |
| 908 | 908 | |
| 909 | 909 | try testing.expect((try c.to(u256)) == op1 * op2); |
| 910 | 910 | } |
| ... | ... | @@ -915,7 +915,7 @@ test "big.int mul alias r with a" { |
| 915 | 915 | var b = try Managed.initSet(testing.allocator, 2); |
| 916 | 916 | defer b.deinit(); |
| 917 | 917 | |
| 918 | | try a.mul(a.toConst(), b.toConst()); |
| 918 | try a.mul(&a, &b); |
| 919 | 919 | |
| 920 | 920 | try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb)); |
| 921 | 921 | } |
| ... | ... | @@ -926,7 +926,7 @@ test "big.int mul alias r with b" { |
| 926 | 926 | var b = try Managed.initSet(testing.allocator, 2); |
| 927 | 927 | defer b.deinit(); |
| 928 | 928 | |
| 929 | | try a.mul(b.toConst(), a.toConst()); |
| 929 | try a.mul(&b, &a); |
| 930 | 930 | |
| 931 | 931 | try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb)); |
| 932 | 932 | } |
| ... | ... | @@ -935,7 +935,7 @@ test "big.int mul alias r with a and b" { |
| 935 | 935 | var a = try Managed.initSet(testing.allocator, maxInt(Limb)); |
| 936 | 936 | defer a.deinit(); |
| 937 | 937 | |
| 938 | | try a.mul(a.toConst(), a.toConst()); |
| 938 | try a.mul(&a, &a); |
| 939 | 939 | |
| 940 | 940 | try testing.expect((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb)); |
| 941 | 941 | } |
| ... | ... | @@ -948,7 +948,7 @@ test "big.int mul a*0" { |
| 948 | 948 | |
| 949 | 949 | var c = try Managed.init(testing.allocator); |
| 950 | 950 | defer c.deinit(); |
| 951 | | try c.mul(a.toConst(), b.toConst()); |
| 951 | try c.mul(&a, &b); |
| 952 | 952 | |
| 953 | 953 | try testing.expect((try c.to(u32)) == 0); |
| 954 | 954 | } |
| ... | ... | @@ -961,7 +961,7 @@ test "big.int mul 0*0" { |
| 961 | 961 | |
| 962 | 962 | var c = try Managed.init(testing.allocator); |
| 963 | 963 | defer c.deinit(); |
| 964 | | try c.mul(a.toConst(), b.toConst()); |
| 964 | try c.mul(&a, &b); |
| 965 | 965 | |
| 966 | 966 | try testing.expect((try c.to(u32)) == 0); |
| 967 | 967 | } |
| ... | ... | @@ -981,8 +981,8 @@ test "big.int mul large" { |
| 981 | 981 | } |
| 982 | 982 | a.setMetadata(true, 50); |
| 983 | 983 | |
| 984 | | try b.mul(a.toConst(), a.toConst()); |
| 985 | | try c.sqr(a.toConst()); |
| 984 | try b.mul(&a, &a); |
| 985 | try c.sqr(&a); |
| 986 | 986 | |
| 987 | 987 | try testing.expect(b.eq(c)); |
| 988 | 988 | } |
| ... | ... | @@ -995,7 +995,7 @@ test "big.int mulWrap single-single unsigned" { |
| 995 | 995 | |
| 996 | 996 | var c = try Managed.init(testing.allocator); |
| 997 | 997 | defer c.deinit(); |
| 998 | | try c.mulWrap(a.toConst(), b.toConst(), .unsigned, 17); |
| 998 | try c.mulWrap(&a, &b, .unsigned, 17); |
| 999 | 999 | |
| 1000 | 1000 | try testing.expect((try c.to(u17)) == 59836); |
| 1001 | 1001 | } |
| ... | ... | @@ -1008,7 +1008,7 @@ test "big.int mulWrap single-single signed" { |
| 1008 | 1008 | |
| 1009 | 1009 | var c = try Managed.init(testing.allocator); |
| 1010 | 1010 | defer c.deinit(); |
| 1011 | | try c.mulWrap(a.toConst(), b.toConst(), .signed, 17); |
| 1011 | try c.mulWrap(&a, &b, .signed, 17); |
| 1012 | 1012 | |
| 1013 | 1013 | try testing.expect((try c.to(i17)) == -59836); |
| 1014 | 1014 | } |
| ... | ... | @@ -1023,7 +1023,7 @@ test "big.int mulWrap multi-multi unsigned" { |
| 1023 | 1023 | |
| 1024 | 1024 | var c = try Managed.init(testing.allocator); |
| 1025 | 1025 | defer c.deinit(); |
| 1026 | | try c.mulWrap(a.toConst(), b.toConst(), .unsigned, 65); |
| 1026 | try c.mulWrap(&a, &b, .unsigned, 65); |
| 1027 | 1027 | |
| 1028 | 1028 | try testing.expect((try c.to(u128)) == (op1 * op2) & ((1 << 65) - 1)); |
| 1029 | 1029 | } |
| ... | ... | @@ -1036,7 +1036,7 @@ test "big.int mulWrap multi-multi signed" { |
| 1036 | 1036 | |
| 1037 | 1037 | var c = try Managed.init(testing.allocator); |
| 1038 | 1038 | defer c.deinit(); |
| 1039 | | try c.mulWrap(a.toConst(), b.toConst(), .signed, @bitSizeOf(SignedDoubleLimb)); |
| 1039 | try c.mulWrap(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb)); |
| 1040 | 1040 | |
| 1041 | 1041 | try testing.expect((try c.to(SignedDoubleLimb)) == minInt(SignedDoubleLimb) + 2); |
| 1042 | 1042 | } |
| ... | ... | @@ -1058,9 +1058,9 @@ test "big.int mulWrap large" { |
| 1058 | 1058 | |
| 1059 | 1059 | const testbits = @bitSizeOf(Limb) * 64 + 45; |
| 1060 | 1060 | |
| 1061 | | try b.mulWrap(a.toConst(), a.toConst(), .signed, testbits); |
| 1062 | | try c.sqr(a.toConst()); |
| 1063 | | try c.truncate(c.toConst(), .signed, testbits); |
| 1061 | try b.mulWrap(&a, &a, .signed, testbits); |
| 1062 | try c.sqr(&a); |
| 1063 | try c.truncate(&c, .signed, testbits); |
| 1064 | 1064 | |
| 1065 | 1065 | try testing.expect(b.eq(c)); |
| 1066 | 1066 | } |
| ... | ... | @@ -1075,7 +1075,7 @@ test "big.int div single-half no rem" { |
| 1075 | 1075 | defer q.deinit(); |
| 1076 | 1076 | var r = try Managed.init(testing.allocator); |
| 1077 | 1077 | defer r.deinit(); |
| 1078 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1078 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1079 | 1079 | |
| 1080 | 1080 | try testing.expect((try q.to(u32)) == 10); |
| 1081 | 1081 | try testing.expect((try r.to(u32)) == 0); |
| ... | ... | @@ -1091,7 +1091,7 @@ test "big.int div single-half with rem" { |
| 1091 | 1091 | defer q.deinit(); |
| 1092 | 1092 | var r = try Managed.init(testing.allocator); |
| 1093 | 1093 | defer r.deinit(); |
| 1094 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1094 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1095 | 1095 | |
| 1096 | 1096 | try testing.expect((try q.to(u32)) == 9); |
| 1097 | 1097 | try testing.expect((try r.to(u32)) == 4); |
| ... | ... | @@ -1108,7 +1108,7 @@ test "big.int div single-single no rem" { |
| 1108 | 1108 | defer q.deinit(); |
| 1109 | 1109 | var r = try Managed.init(testing.allocator); |
| 1110 | 1110 | defer r.deinit(); |
| 1111 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1111 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1112 | 1112 | |
| 1113 | 1113 | try testing.expect((try q.to(u32)) == 131072); |
| 1114 | 1114 | try testing.expect((try r.to(u32)) == 0); |
| ... | ... | @@ -1124,7 +1124,7 @@ test "big.int div single-single with rem" { |
| 1124 | 1124 | defer q.deinit(); |
| 1125 | 1125 | var r = try Managed.init(testing.allocator); |
| 1126 | 1126 | defer r.deinit(); |
| 1127 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1127 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1128 | 1128 | |
| 1129 | 1129 | try testing.expect((try q.to(u64)) == 131072); |
| 1130 | 1130 | try testing.expect((try r.to(u64)) == 8589934592); |
| ... | ... | @@ -1143,7 +1143,7 @@ test "big.int div multi-single no rem" { |
| 1143 | 1143 | defer q.deinit(); |
| 1144 | 1144 | var r = try Managed.init(testing.allocator); |
| 1145 | 1145 | defer r.deinit(); |
| 1146 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1146 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1147 | 1147 | |
| 1148 | 1148 | try testing.expect((try q.to(u64)) == op1 / op2); |
| 1149 | 1149 | try testing.expect((try r.to(u64)) == 0); |
| ... | ... | @@ -1162,7 +1162,7 @@ test "big.int div multi-single with rem" { |
| 1162 | 1162 | defer q.deinit(); |
| 1163 | 1163 | var r = try Managed.init(testing.allocator); |
| 1164 | 1164 | defer r.deinit(); |
| 1165 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1165 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1166 | 1166 | |
| 1167 | 1167 | try testing.expect((try q.to(u64)) == op1 / op2); |
| 1168 | 1168 | try testing.expect((try r.to(u64)) == 3); |
| ... | ... | @@ -1181,7 +1181,7 @@ test "big.int div multi>2-single" { |
| 1181 | 1181 | defer q.deinit(); |
| 1182 | 1182 | var r = try Managed.init(testing.allocator); |
| 1183 | 1183 | defer r.deinit(); |
| 1184 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1184 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1185 | 1185 | |
| 1186 | 1186 | try testing.expect((try q.to(u128)) == op1 / op2); |
| 1187 | 1187 | try testing.expect((try r.to(u32)) == 0x3e4e); |
| ... | ... | @@ -1197,7 +1197,7 @@ test "big.int div single-single q < r" { |
| 1197 | 1197 | defer q.deinit(); |
| 1198 | 1198 | var r = try Managed.init(testing.allocator); |
| 1199 | 1199 | defer r.deinit(); |
| 1200 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1200 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1201 | 1201 | |
| 1202 | 1202 | try testing.expect((try q.to(u64)) == 0); |
| 1203 | 1203 | try testing.expect((try r.to(u64)) == 0x0078f432); |
| ... | ... | @@ -1213,7 +1213,7 @@ test "big.int div single-single q == r" { |
| 1213 | 1213 | defer q.deinit(); |
| 1214 | 1214 | var r = try Managed.init(testing.allocator); |
| 1215 | 1215 | defer r.deinit(); |
| 1216 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1216 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1217 | 1217 | |
| 1218 | 1218 | try testing.expect((try q.to(u64)) == 1); |
| 1219 | 1219 | try testing.expect((try r.to(u64)) == 0); |
| ... | ... | @@ -1225,7 +1225,7 @@ test "big.int div q=0 alias" { |
| 1225 | 1225 | var b = try Managed.initSet(testing.allocator, 10); |
| 1226 | 1226 | defer b.deinit(); |
| 1227 | 1227 | |
| 1228 | | try Managed.divTrunc(&a, &b, a.toConst(), b.toConst()); |
| 1228 | try Managed.divTrunc(&a, &b, &a, &b); |
| 1229 | 1229 | |
| 1230 | 1230 | try testing.expect((try a.to(u64)) == 0); |
| 1231 | 1231 | try testing.expect((try b.to(u64)) == 3); |
| ... | ... | @@ -1243,7 +1243,7 @@ test "big.int div multi-multi q < r" { |
| 1243 | 1243 | defer q.deinit(); |
| 1244 | 1244 | var r = try Managed.init(testing.allocator); |
| 1245 | 1245 | defer r.deinit(); |
| 1246 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1246 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1247 | 1247 | |
| 1248 | 1248 | try testing.expect((try q.to(u128)) == 0); |
| 1249 | 1249 | try testing.expect((try r.to(u128)) == op1); |
| ... | ... | @@ -1262,7 +1262,7 @@ test "big.int div trunc single-single +/+" { |
| 1262 | 1262 | defer q.deinit(); |
| 1263 | 1263 | var r = try Managed.init(testing.allocator); |
| 1264 | 1264 | defer r.deinit(); |
| 1265 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1265 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1266 | 1266 | |
| 1267 | 1267 | // n = q * d + r |
| 1268 | 1268 | // 5 = 1 * 3 + 2 |
| ... | ... | @@ -1286,7 +1286,7 @@ test "big.int div trunc single-single -/+" { |
| 1286 | 1286 | defer q.deinit(); |
| 1287 | 1287 | var r = try Managed.init(testing.allocator); |
| 1288 | 1288 | defer r.deinit(); |
| 1289 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1289 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1290 | 1290 | |
| 1291 | 1291 | // n = q * d + r |
| 1292 | 1292 | // -5 = 1 * -3 - 2 |
| ... | ... | @@ -1310,7 +1310,7 @@ test "big.int div trunc single-single +/-" { |
| 1310 | 1310 | defer q.deinit(); |
| 1311 | 1311 | var r = try Managed.init(testing.allocator); |
| 1312 | 1312 | defer r.deinit(); |
| 1313 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1313 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1314 | 1314 | |
| 1315 | 1315 | // n = q * d + r |
| 1316 | 1316 | // 5 = -1 * -3 + 2 |
| ... | ... | @@ -1334,7 +1334,7 @@ test "big.int div trunc single-single -/-" { |
| 1334 | 1334 | defer q.deinit(); |
| 1335 | 1335 | var r = try Managed.init(testing.allocator); |
| 1336 | 1336 | defer r.deinit(); |
| 1337 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1337 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1338 | 1338 | |
| 1339 | 1339 | // n = q * d + r |
| 1340 | 1340 | // -5 = 1 * -3 - 2 |
| ... | ... | @@ -1361,7 +1361,7 @@ test "big.int divFloor #10932" { |
| 1361 | 1361 | var mod = try Managed.init(testing.allocator); |
| 1362 | 1362 | defer mod.deinit(); |
| 1363 | 1363 | |
| 1364 | | try res.divFloor(&mod, a.toConst(), b.toConst()); |
| 1364 | try res.divFloor(&mod, &a, &b); |
| 1365 | 1365 | |
| 1366 | 1366 | const ress = try res.toString(testing.allocator, 16, .lower); |
| 1367 | 1367 | defer testing.allocator.free(ress); |
| ... | ... | @@ -1385,7 +1385,7 @@ test "big.int divFloor #11166" { |
| 1385 | 1385 | var mod = try Managed.init(testing.allocator); |
| 1386 | 1386 | defer mod.deinit(); |
| 1387 | 1387 | |
| 1388 | | try res.divFloor(&mod, a.toConst(), b.toConst()); |
| 1388 | try res.divFloor(&mod, &a, &b); |
| 1389 | 1389 | |
| 1390 | 1390 | const ress = try res.toString(testing.allocator, 10, .lower); |
| 1391 | 1391 | defer testing.allocator.free(ress); |
| ... | ... | @@ -1409,7 +1409,7 @@ test "big.int gcd #10932" { |
| 1409 | 1409 | try a.setString(10, "3000000000000000000000000000000000000000000000000000000000000000000000001461501637330902918203684832716283019655932542975000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); |
| 1410 | 1410 | try b.setString(10, "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200001001500000000000000000100000000040000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000003000000000000000000000000000000000000000000000000000058715661000000000000000000000000000000000000023553252000000000180000000000000000000000000000000000000000000000000250000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001005000002000000000000000000000000000000000000000021000000001000000000000000000000000100000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000200000000000000000000004000000000000000000000000000000000000000000000301000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); |
| 1411 | 1411 | |
| 1412 | | try res.gcd(a, b); |
| 1412 | try res.gcd(&a, &b); |
| 1413 | 1413 | |
| 1414 | 1414 | const ress = try res.toString(testing.allocator, 16, .lower); |
| 1415 | 1415 | defer testing.allocator.free(ress); |
| ... | ... | @@ -1429,7 +1429,7 @@ test "big.int bitAnd #10932" { |
| 1429 | 1429 | try a.setString(10, "154954885951624787839743960731760616696"); |
| 1430 | 1430 | try b.setString(10, "55000000000915215865915724129619485917228346934191537590366734850266784978214506142389798064826139649163838075568111457203909393174933092857416500785632012953993352521899237655507306575657169267399324107627651067352600878339870446048204062696260567762088867991835386857942106708741836433444432529637331429212430394179472179237695833247299409249810963487516399177133175950185719220422442438098353430605822151595560743492661038899294517012784306863064670126197566982968906306814338148792888550378533207318063660581924736840687332023636827401670268933229183389040490792300121030647791095178823932734160000000000000000000000000000000000000555555550000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); |
| 1431 | 1431 | |
| 1432 | | try res.bitAnd(a, b); |
| 1432 | try res.bitAnd(&a, &b); |
| 1433 | 1433 | |
| 1434 | 1434 | try testing.expect((try res.to(i32)) == 0); |
| 1435 | 1435 | } |
| ... | ... | @@ -1447,7 +1447,7 @@ test "big.int div floor single-single +/+" { |
| 1447 | 1447 | defer q.deinit(); |
| 1448 | 1448 | var r = try Managed.init(testing.allocator); |
| 1449 | 1449 | defer r.deinit(); |
| 1450 | | try Managed.divFloor(&q, &r, a.toConst(), b.toConst()); |
| 1450 | try Managed.divFloor(&q, &r, &a, &b); |
| 1451 | 1451 | |
| 1452 | 1452 | // n = q * d + r |
| 1453 | 1453 | // 5 = 1 * 3 + 2 |
| ... | ... | @@ -1471,7 +1471,7 @@ test "big.int div floor single-single -/+" { |
| 1471 | 1471 | defer q.deinit(); |
| 1472 | 1472 | var r = try Managed.init(testing.allocator); |
| 1473 | 1473 | defer r.deinit(); |
| 1474 | | try Managed.divFloor(&q, &r, a.toConst(), b.toConst()); |
| 1474 | try Managed.divFloor(&q, &r, &a, &b); |
| 1475 | 1475 | |
| 1476 | 1476 | // n = q * d + r |
| 1477 | 1477 | // -5 = -2 * 3 + 1 |
| ... | ... | @@ -1495,7 +1495,7 @@ test "big.int div floor single-single +/-" { |
| 1495 | 1495 | defer q.deinit(); |
| 1496 | 1496 | var r = try Managed.init(testing.allocator); |
| 1497 | 1497 | defer r.deinit(); |
| 1498 | | try Managed.divFloor(&q, &r, a.toConst(), b.toConst()); |
| 1498 | try Managed.divFloor(&q, &r, &a, &b); |
| 1499 | 1499 | |
| 1500 | 1500 | // n = q * d + r |
| 1501 | 1501 | // 5 = -2 * -3 - 1 |
| ... | ... | @@ -1519,7 +1519,7 @@ test "big.int div floor single-single -/-" { |
| 1519 | 1519 | defer q.deinit(); |
| 1520 | 1520 | var r = try Managed.init(testing.allocator); |
| 1521 | 1521 | defer r.deinit(); |
| 1522 | | try Managed.divFloor(&q, &r, a.toConst(), b.toConst()); |
| 1522 | try Managed.divFloor(&q, &r, &a, &b); |
| 1523 | 1523 | |
| 1524 | 1524 | // n = q * d + r |
| 1525 | 1525 | // -5 = 2 * -3 + 1 |
| ... | ... | @@ -1543,7 +1543,7 @@ test "big.int div floor no remainder negative quotient" { |
| 1543 | 1543 | defer q.deinit(); |
| 1544 | 1544 | var r = try Managed.init(testing.allocator); |
| 1545 | 1545 | defer r.deinit(); |
| 1546 | | try Managed.divFloor(&q, &r, a.toConst(), b.toConst()); |
| 1546 | try Managed.divFloor(&q, &r, &a, &b); |
| 1547 | 1547 | |
| 1548 | 1548 | try testing.expect((try q.to(i32)) == -0x80000000); |
| 1549 | 1549 | try testing.expect((try r.to(i32)) == 0); |
| ... | ... | @@ -1562,7 +1562,7 @@ test "big.int div floor negative close to zero" { |
| 1562 | 1562 | defer q.deinit(); |
| 1563 | 1563 | var r = try Managed.init(testing.allocator); |
| 1564 | 1564 | defer r.deinit(); |
| 1565 | | try Managed.divFloor(&q, &r, a.toConst(), b.toConst()); |
| 1565 | try Managed.divFloor(&q, &r, &a, &b); |
| 1566 | 1566 | |
| 1567 | 1567 | try testing.expect((try q.to(i32)) == -1); |
| 1568 | 1568 | try testing.expect((try r.to(i32)) == 10); |
| ... | ... | @@ -1581,7 +1581,7 @@ test "big.int div floor positive close to zero" { |
| 1581 | 1581 | defer q.deinit(); |
| 1582 | 1582 | var r = try Managed.init(testing.allocator); |
| 1583 | 1583 | defer r.deinit(); |
| 1584 | | try Managed.divFloor(&q, &r, a.toConst(), b.toConst()); |
| 1584 | try Managed.divFloor(&q, &r, &a, &b); |
| 1585 | 1585 | |
| 1586 | 1586 | try testing.expect((try q.to(i32)) == 0); |
| 1587 | 1587 | try testing.expect((try r.to(i32)) == 10); |
| ... | ... | @@ -1597,7 +1597,7 @@ test "big.int div multi-multi with rem" { |
| 1597 | 1597 | defer q.deinit(); |
| 1598 | 1598 | var r = try Managed.init(testing.allocator); |
| 1599 | 1599 | defer r.deinit(); |
| 1600 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1600 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1601 | 1601 | |
| 1602 | 1602 | try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b); |
| 1603 | 1603 | try testing.expect((try r.to(u128)) == 0x28de0acacd806823638); |
| ... | ... | @@ -1613,7 +1613,7 @@ test "big.int div multi-multi no rem" { |
| 1613 | 1613 | defer q.deinit(); |
| 1614 | 1614 | var r = try Managed.init(testing.allocator); |
| 1615 | 1615 | defer r.deinit(); |
| 1616 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1616 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1617 | 1617 | |
| 1618 | 1618 | try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b); |
| 1619 | 1619 | try testing.expect((try r.to(u128)) == 0); |
| ... | ... | @@ -1629,7 +1629,7 @@ test "big.int div multi-multi (2 branch)" { |
| 1629 | 1629 | defer q.deinit(); |
| 1630 | 1630 | var r = try Managed.init(testing.allocator); |
| 1631 | 1631 | defer r.deinit(); |
| 1632 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1632 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1633 | 1633 | |
| 1634 | 1634 | try testing.expect((try q.to(u128)) == 0x10000000000000000); |
| 1635 | 1635 | try testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111); |
| ... | ... | @@ -1645,7 +1645,7 @@ test "big.int div multi-multi (3.1/3.3 branch)" { |
| 1645 | 1645 | defer q.deinit(); |
| 1646 | 1646 | var r = try Managed.init(testing.allocator); |
| 1647 | 1647 | defer r.deinit(); |
| 1648 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1648 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1649 | 1649 | |
| 1650 | 1650 | try testing.expect((try q.to(u128)) == 0xfffffffffffffffffff); |
| 1651 | 1651 | try testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282); |
| ... | ... | @@ -1661,7 +1661,7 @@ test "big.int div multi-single zero-limb trailing" { |
| 1661 | 1661 | defer q.deinit(); |
| 1662 | 1662 | var r = try Managed.init(testing.allocator); |
| 1663 | 1663 | defer r.deinit(); |
| 1664 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1664 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1665 | 1665 | |
| 1666 | 1666 | var expected = try Managed.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000); |
| 1667 | 1667 | defer expected.deinit(); |
| ... | ... | @@ -1679,7 +1679,7 @@ test "big.int div multi-multi zero-limb trailing (with rem)" { |
| 1679 | 1679 | defer q.deinit(); |
| 1680 | 1680 | var r = try Managed.init(testing.allocator); |
| 1681 | 1681 | defer r.deinit(); |
| 1682 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1682 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1683 | 1683 | |
| 1684 | 1684 | try testing.expect((try q.to(u128)) == 0x10000000000000000); |
| 1685 | 1685 | |
| ... | ... | @@ -1698,7 +1698,7 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li |
| 1698 | 1698 | defer q.deinit(); |
| 1699 | 1699 | var r = try Managed.init(testing.allocator); |
| 1700 | 1700 | defer r.deinit(); |
| 1701 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1701 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1702 | 1702 | |
| 1703 | 1703 | try testing.expect((try q.to(u128)) == 0x1); |
| 1704 | 1704 | |
| ... | ... | @@ -1717,7 +1717,7 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li |
| 1717 | 1717 | defer q.deinit(); |
| 1718 | 1718 | var r = try Managed.init(testing.allocator); |
| 1719 | 1719 | defer r.deinit(); |
| 1720 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1720 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1721 | 1721 | |
| 1722 | 1722 | const qs = try q.toString(testing.allocator, 16, .lower); |
| 1723 | 1723 | defer testing.allocator.free(qs); |
| ... | ... | @@ -1741,7 +1741,7 @@ test "big.int div multi-multi fuzz case #1" { |
| 1741 | 1741 | defer q.deinit(); |
| 1742 | 1742 | var r = try Managed.init(testing.allocator); |
| 1743 | 1743 | defer r.deinit(); |
| 1744 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1744 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1745 | 1745 | |
| 1746 | 1746 | const qs = try q.toString(testing.allocator, 16, .lower); |
| 1747 | 1747 | defer testing.allocator.free(qs); |
| ... | ... | @@ -1765,7 +1765,7 @@ test "big.int div multi-multi fuzz case #2" { |
| 1765 | 1765 | defer q.deinit(); |
| 1766 | 1766 | var r = try Managed.init(testing.allocator); |
| 1767 | 1767 | defer r.deinit(); |
| 1768 | | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1768 | try Managed.divTrunc(&q, &r, &a, &b); |
| 1769 | 1769 | |
| 1770 | 1770 | const qs = try q.toString(testing.allocator, 16, .lower); |
| 1771 | 1771 | defer testing.allocator.free(qs); |
| ... | ... | @@ -1780,7 +1780,7 @@ test "big.int truncate single unsigned" { |
| 1780 | 1780 | var a = try Managed.initSet(testing.allocator, maxInt(u47)); |
| 1781 | 1781 | defer a.deinit(); |
| 1782 | 1782 | |
| 1783 | | try a.truncate(a.toConst(), .unsigned, 17); |
| 1783 | try a.truncate(&a, .unsigned, 17); |
| 1784 | 1784 | |
| 1785 | 1785 | try testing.expect((try a.to(u17)) == maxInt(u17)); |
| 1786 | 1786 | } |
| ... | ... | @@ -1789,7 +1789,7 @@ test "big.int truncate single signed" { |
| 1789 | 1789 | var a = try Managed.initSet(testing.allocator, 0x1_0000); |
| 1790 | 1790 | defer a.deinit(); |
| 1791 | 1791 | |
| 1792 | | try a.truncate(a.toConst(), .signed, 17); |
| 1792 | try a.truncate(&a, .signed, 17); |
| 1793 | 1793 | |
| 1794 | 1794 | try testing.expect((try a.to(i17)) == minInt(i17)); |
| 1795 | 1795 | } |
| ... | ... | @@ -1798,7 +1798,7 @@ test "big.int truncate multi to single unsigned" { |
| 1798 | 1798 | var a = try Managed.initSet(testing.allocator, (maxInt(Limb) + 1) | 0x1234_5678_9ABC_DEF0); |
| 1799 | 1799 | defer a.deinit(); |
| 1800 | 1800 | |
| 1801 | | try a.truncate(a.toConst(), .unsigned, 27); |
| 1801 | try a.truncate(&a, .unsigned, 27); |
| 1802 | 1802 | |
| 1803 | 1803 | try testing.expect((try a.to(u27)) == 0x2BC_DEF0); |
| 1804 | 1804 | } |
| ... | ... | @@ -1807,7 +1807,7 @@ test "big.int truncate multi to single signed" { |
| 1807 | 1807 | var a = try Managed.initSet(testing.allocator, maxInt(Limb) << 10); |
| 1808 | 1808 | defer a.deinit(); |
| 1809 | 1809 | |
| 1810 | | try a.truncate(a.toConst(), .signed, @bitSizeOf(i11)); |
| 1810 | try a.truncate(&a, .signed, @bitSizeOf(i11)); |
| 1811 | 1811 | |
| 1812 | 1812 | try testing.expect((try a.to(i11)) == minInt(i11)); |
| 1813 | 1813 | } |
| ... | ... | @@ -1819,7 +1819,7 @@ test "big.int truncate multi to multi unsigned" { |
| 1819 | 1819 | var a = try Managed.initSet(testing.allocator, maxInt(SignedDoubleLimb)); |
| 1820 | 1820 | defer a.deinit(); |
| 1821 | 1821 | |
| 1822 | | try a.truncate(a.toConst(), .unsigned, bits - 1); |
| 1822 | try a.truncate(&a, .unsigned, bits - 1); |
| 1823 | 1823 | |
| 1824 | 1824 | try testing.expect((try a.to(Int)) == maxInt(Int)); |
| 1825 | 1825 | } |
| ... | ... | @@ -1828,7 +1828,7 @@ test "big.int truncate multi to multi signed" { |
| 1828 | 1828 | var a = try Managed.initSet(testing.allocator, 3 << @bitSizeOf(Limb)); |
| 1829 | 1829 | defer a.deinit(); |
| 1830 | 1830 | |
| 1831 | | try a.truncate(a.toConst(), .signed, @bitSizeOf(Limb) + 1); |
| 1831 | try a.truncate(&a, .signed, @bitSizeOf(Limb) + 1); |
| 1832 | 1832 | |
| 1833 | 1833 | try testing.expect((try a.to(std.meta.Int(.signed, @bitSizeOf(Limb) + 1))) == -1 << @bitSizeOf(Limb)); |
| 1834 | 1834 | } |
| ... | ... | @@ -1837,7 +1837,7 @@ test "big.int truncate negative multi to single" { |
| 1837 | 1837 | var a = try Managed.initSet(testing.allocator, -@as(SignedDoubleLimb, maxInt(Limb) + 1)); |
| 1838 | 1838 | defer a.deinit(); |
| 1839 | 1839 | |
| 1840 | | try a.truncate(a.toConst(), .signed, @bitSizeOf(i17)); |
| 1840 | try a.truncate(&a, .signed, @bitSizeOf(i17)); |
| 1841 | 1841 | |
| 1842 | 1842 | try testing.expect((try a.to(i17)) == 0); |
| 1843 | 1843 | } |
| ... | ... | @@ -1845,11 +1845,11 @@ test "big.int truncate negative multi to single" { |
| 1845 | 1845 | test "big.int truncate multi unsigned many" { |
| 1846 | 1846 | var a = try Managed.initSet(testing.allocator, 1); |
| 1847 | 1847 | defer a.deinit(); |
| 1848 | | try a.shiftLeft(a, 1023); |
| 1848 | try a.shiftLeft(&a, 1023); |
| 1849 | 1849 | |
| 1850 | 1850 | var b = try Managed.init(testing.allocator); |
| 1851 | 1851 | defer b.deinit(); |
| 1852 | | try b.truncate(a.toConst(), .signed, @bitSizeOf(i1)); |
| 1852 | try b.truncate(&a, .signed, @bitSizeOf(i1)); |
| 1853 | 1853 | |
| 1854 | 1854 | try testing.expect((try b.to(i1)) == 0); |
| 1855 | 1855 | } |
| ... | ... | @@ -1858,7 +1858,7 @@ test "big.int saturate single signed positive" { |
| 1858 | 1858 | var a = try Managed.initSet(testing.allocator, 0xBBBB_BBBB); |
| 1859 | 1859 | defer a.deinit(); |
| 1860 | 1860 | |
| 1861 | | try a.saturate(a.toConst(), .signed, 17); |
| 1861 | try a.saturate(&a, .signed, 17); |
| 1862 | 1862 | |
| 1863 | 1863 | try testing.expect((try a.to(i17)) == maxInt(i17)); |
| 1864 | 1864 | } |
| ... | ... | @@ -1867,7 +1867,7 @@ test "big.int saturate single signed negative" { |
| 1867 | 1867 | var a = try Managed.initSet(testing.allocator, -1_234_567); |
| 1868 | 1868 | defer a.deinit(); |
| 1869 | 1869 | |
| 1870 | | try a.saturate(a.toConst(), .signed, 17); |
| 1870 | try a.saturate(&a, .signed, 17); |
| 1871 | 1871 | |
| 1872 | 1872 | try testing.expect((try a.to(i17)) == minInt(i17)); |
| 1873 | 1873 | } |
| ... | ... | @@ -1876,7 +1876,7 @@ test "big.int saturate single signed" { |
| 1876 | 1876 | var a = try Managed.initSet(testing.allocator, maxInt(i17) - 1); |
| 1877 | 1877 | defer a.deinit(); |
| 1878 | 1878 | |
| 1879 | | try a.saturate(a.toConst(), .signed, 17); |
| 1879 | try a.saturate(&a, .signed, 17); |
| 1880 | 1880 | |
| 1881 | 1881 | try testing.expect((try a.to(i17)) == maxInt(i17) - 1); |
| 1882 | 1882 | } |
| ... | ... | @@ -1885,7 +1885,7 @@ test "big.int saturate multi signed" { |
| 1885 | 1885 | var a = try Managed.initSet(testing.allocator, maxInt(Limb) << @bitSizeOf(SignedDoubleLimb)); |
| 1886 | 1886 | defer a.deinit(); |
| 1887 | 1887 | |
| 1888 | | try a.saturate(a.toConst(), .signed, @bitSizeOf(SignedDoubleLimb)); |
| 1888 | try a.saturate(&a, .signed, @bitSizeOf(SignedDoubleLimb)); |
| 1889 | 1889 | |
| 1890 | 1890 | try testing.expect((try a.to(SignedDoubleLimb)) == maxInt(SignedDoubleLimb)); |
| 1891 | 1891 | } |
| ... | ... | @@ -1894,7 +1894,7 @@ test "big.int saturate single unsigned" { |
| 1894 | 1894 | var a = try Managed.initSet(testing.allocator, 0xFEFE_FEFE); |
| 1895 | 1895 | defer a.deinit(); |
| 1896 | 1896 | |
| 1897 | | try a.saturate(a.toConst(), .unsigned, 23); |
| 1897 | try a.saturate(&a, .unsigned, 23); |
| 1898 | 1898 | |
| 1899 | 1899 | try testing.expect((try a.to(u23)) == maxInt(u23)); |
| 1900 | 1900 | } |
| ... | ... | @@ -1903,7 +1903,7 @@ test "big.int saturate multi unsigned zero" { |
| 1903 | 1903 | var a = try Managed.initSet(testing.allocator, -1); |
| 1904 | 1904 | defer a.deinit(); |
| 1905 | 1905 | |
| 1906 | | try a.saturate(a.toConst(), .unsigned, @bitSizeOf(DoubleLimb)); |
| 1906 | try a.saturate(&a, .unsigned, @bitSizeOf(DoubleLimb)); |
| 1907 | 1907 | |
| 1908 | 1908 | try testing.expect(a.eqZero()); |
| 1909 | 1909 | } |
| ... | ... | @@ -1912,7 +1912,7 @@ test "big.int saturate multi unsigned" { |
| 1912 | 1912 | var a = try Managed.initSet(testing.allocator, maxInt(Limb) << @bitSizeOf(DoubleLimb)); |
| 1913 | 1913 | defer a.deinit(); |
| 1914 | 1914 | |
| 1915 | | try a.saturate(a.toConst(), .unsigned, @bitSizeOf(DoubleLimb)); |
| 1915 | try a.saturate(&a, .unsigned, @bitSizeOf(DoubleLimb)); |
| 1916 | 1916 | |
| 1917 | 1917 | try testing.expect((try a.to(DoubleLimb)) == maxInt(DoubleLimb)); |
| 1918 | 1918 | } |
| ... | ... | @@ -1920,7 +1920,7 @@ test "big.int saturate multi unsigned" { |
| 1920 | 1920 | test "big.int shift-right single" { |
| 1921 | 1921 | var a = try Managed.initSet(testing.allocator, 0xffff0000); |
| 1922 | 1922 | defer a.deinit(); |
| 1923 | | try a.shiftRight(a, 16); |
| 1923 | try a.shiftRight(&a, 16); |
| 1924 | 1924 | |
| 1925 | 1925 | try testing.expect((try a.to(u32)) == 0xffff); |
| 1926 | 1926 | } |
| ... | ... | @@ -1928,21 +1928,21 @@ test "big.int shift-right single" { |
| 1928 | 1928 | test "big.int shift-right multi" { |
| 1929 | 1929 | var a = try Managed.initSet(testing.allocator, 0xffff0000eeee1111dddd2222cccc3333); |
| 1930 | 1930 | defer a.deinit(); |
| 1931 | | try a.shiftRight(a, 67); |
| 1931 | try a.shiftRight(&a, 67); |
| 1932 | 1932 | |
| 1933 | 1933 | try testing.expect((try a.to(u64)) == 0x1fffe0001dddc222); |
| 1934 | 1934 | |
| 1935 | 1935 | try a.set(0xffff0000eeee1111dddd2222cccc3333); |
| 1936 | | try a.shiftRight(a, 63); |
| 1937 | | try a.shiftRight(a, 63); |
| 1938 | | try a.shiftRight(a, 2); |
| 1936 | try a.shiftRight(&a, 63); |
| 1937 | try a.shiftRight(&a, 63); |
| 1938 | try a.shiftRight(&a, 2); |
| 1939 | 1939 | try testing.expect(a.eqZero()); |
| 1940 | 1940 | } |
| 1941 | 1941 | |
| 1942 | 1942 | test "big.int shift-left single" { |
| 1943 | 1943 | var a = try Managed.initSet(testing.allocator, 0xffff); |
| 1944 | 1944 | defer a.deinit(); |
| 1945 | | try a.shiftLeft(a, 16); |
| 1945 | try a.shiftLeft(&a, 16); |
| 1946 | 1946 | |
| 1947 | 1947 | try testing.expect((try a.to(u64)) == 0xffff0000); |
| 1948 | 1948 | } |
| ... | ... | @@ -1950,7 +1950,7 @@ test "big.int shift-left single" { |
| 1950 | 1950 | test "big.int shift-left multi" { |
| 1951 | 1951 | var a = try Managed.initSet(testing.allocator, 0x1fffe0001dddc222); |
| 1952 | 1952 | defer a.deinit(); |
| 1953 | | try a.shiftLeft(a, 67); |
| 1953 | try a.shiftLeft(&a, 67); |
| 1954 | 1954 | |
| 1955 | 1955 | try testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000); |
| 1956 | 1956 | } |
| ... | ... | @@ -1961,12 +1961,12 @@ test "big.int shift-right negative" { |
| 1961 | 1961 | |
| 1962 | 1962 | var arg = try Managed.initSet(testing.allocator, -20); |
| 1963 | 1963 | defer arg.deinit(); |
| 1964 | | try a.shiftRight(arg, 2); |
| 1964 | try a.shiftRight(&arg, 2); |
| 1965 | 1965 | try testing.expect((try a.to(i32)) == -20 >> 2); |
| 1966 | 1966 | |
| 1967 | 1967 | var arg2 = try Managed.initSet(testing.allocator, -5); |
| 1968 | 1968 | defer arg2.deinit(); |
| 1969 | | try a.shiftRight(arg2, 10); |
| 1969 | try a.shiftRight(&arg2, 10); |
| 1970 | 1970 | try testing.expect((try a.to(i32)) == -5 >> 10); |
| 1971 | 1971 | } |
| 1972 | 1972 | |
| ... | ... | @@ -1976,14 +1976,14 @@ test "big.int shift-left negative" { |
| 1976 | 1976 | |
| 1977 | 1977 | var arg = try Managed.initSet(testing.allocator, -10); |
| 1978 | 1978 | defer arg.deinit(); |
| 1979 | | try a.shiftRight(arg, 1232); |
| 1979 | try a.shiftRight(&arg, 1232); |
| 1980 | 1980 | try testing.expect((try a.to(i32)) == -10 >> 1232); |
| 1981 | 1981 | } |
| 1982 | 1982 | |
| 1983 | 1983 | test "big.int sat shift-left simple unsigned" { |
| 1984 | 1984 | var a = try Managed.initSet(testing.allocator, 0xffff); |
| 1985 | 1985 | defer a.deinit(); |
| 1986 | | try a.shiftLeftSat(a, 16, .unsigned, 21); |
| 1986 | try a.shiftLeftSat(&a, 16, .unsigned, 21); |
| 1987 | 1987 | |
| 1988 | 1988 | try testing.expect((try a.to(u64)) == 0x1fffff); |
| 1989 | 1989 | } |
| ... | ... | @@ -1991,7 +1991,7 @@ test "big.int sat shift-left simple unsigned" { |
| 1991 | 1991 | test "big.int sat shift-left simple unsigned no sat" { |
| 1992 | 1992 | var a = try Managed.initSet(testing.allocator, 1); |
| 1993 | 1993 | defer a.deinit(); |
| 1994 | | try a.shiftLeftSat(a, 16, .unsigned, 21); |
| 1994 | try a.shiftLeftSat(&a, 16, .unsigned, 21); |
| 1995 | 1995 | |
| 1996 | 1996 | try testing.expect((try a.to(u64)) == 0x10000); |
| 1997 | 1997 | } |
| ... | ... | @@ -1999,7 +1999,7 @@ test "big.int sat shift-left simple unsigned no sat" { |
| 1999 | 1999 | test "big.int sat shift-left multi unsigned" { |
| 2000 | 2000 | var a = try Managed.initSet(testing.allocator, 16); |
| 2001 | 2001 | defer a.deinit(); |
| 2002 | | try a.shiftLeftSat(a, @bitSizeOf(DoubleLimb) - 3, .unsigned, @bitSizeOf(DoubleLimb) - 1); |
| 2002 | try a.shiftLeftSat(&a, @bitSizeOf(DoubleLimb) - 3, .unsigned, @bitSizeOf(DoubleLimb) - 1); |
| 2003 | 2003 | |
| 2004 | 2004 | try testing.expect((try a.to(DoubleLimb)) == maxInt(DoubleLimb) >> 1); |
| 2005 | 2005 | } |
| ... | ... | @@ -2007,7 +2007,7 @@ test "big.int sat shift-left multi unsigned" { |
| 2007 | 2007 | test "big.int sat shift-left unsigned shift > bitcount" { |
| 2008 | 2008 | var a = try Managed.initSet(testing.allocator, 1); |
| 2009 | 2009 | defer a.deinit(); |
| 2010 | | try a.shiftLeftSat(a, 10, .unsigned, 10); |
| 2010 | try a.shiftLeftSat(&a, 10, .unsigned, 10); |
| 2011 | 2011 | |
| 2012 | 2012 | try testing.expect((try a.to(u10)) == maxInt(u10)); |
| 2013 | 2013 | } |
| ... | ... | @@ -2015,7 +2015,7 @@ test "big.int sat shift-left unsigned shift > bitcount" { |
| 2015 | 2015 | test "big.int sat shift-left unsigned zero" { |
| 2016 | 2016 | var a = try Managed.initSet(testing.allocator, 0); |
| 2017 | 2017 | defer a.deinit(); |
| 2018 | | try a.shiftLeftSat(a, 1, .unsigned, 0); |
| 2018 | try a.shiftLeftSat(&a, 1, .unsigned, 0); |
| 2019 | 2019 | |
| 2020 | 2020 | try testing.expect((try a.to(u64)) == 0); |
| 2021 | 2021 | } |
| ... | ... | @@ -2023,7 +2023,7 @@ test "big.int sat shift-left unsigned zero" { |
| 2023 | 2023 | test "big.int sat shift-left unsigned negative" { |
| 2024 | 2024 | var a = try Managed.initSet(testing.allocator, -100); |
| 2025 | 2025 | defer a.deinit(); |
| 2026 | | try a.shiftLeftSat(a, 0, .unsigned, 0); |
| 2026 | try a.shiftLeftSat(&a, 0, .unsigned, 0); |
| 2027 | 2027 | |
| 2028 | 2028 | try testing.expect((try a.to(u64)) == 0); |
| 2029 | 2029 | } |
| ... | ... | @@ -2031,7 +2031,7 @@ test "big.int sat shift-left unsigned negative" { |
| 2031 | 2031 | test "big.int sat shift-left signed simple negative" { |
| 2032 | 2032 | var a = try Managed.initSet(testing.allocator, -100); |
| 2033 | 2033 | defer a.deinit(); |
| 2034 | | try a.shiftLeftSat(a, 3, .signed, 10); |
| 2034 | try a.shiftLeftSat(&a, 3, .signed, 10); |
| 2035 | 2035 | |
| 2036 | 2036 | try testing.expect((try a.to(i10)) == minInt(i10)); |
| 2037 | 2037 | } |
| ... | ... | @@ -2039,7 +2039,7 @@ test "big.int sat shift-left signed simple negative" { |
| 2039 | 2039 | test "big.int sat shift-left signed simple positive" { |
| 2040 | 2040 | var a = try Managed.initSet(testing.allocator, 100); |
| 2041 | 2041 | defer a.deinit(); |
| 2042 | | try a.shiftLeftSat(a, 3, .signed, 10); |
| 2042 | try a.shiftLeftSat(&a, 3, .signed, 10); |
| 2043 | 2043 | |
| 2044 | 2044 | try testing.expect((try a.to(i10)) == maxInt(i10)); |
| 2045 | 2045 | } |
| ... | ... | @@ -2050,7 +2050,7 @@ test "big.int sat shift-left signed multi positive" { |
| 2050 | 2050 | |
| 2051 | 2051 | var a = try Managed.initSet(testing.allocator, x); |
| 2052 | 2052 | defer a.deinit(); |
| 2053 | | try a.shiftLeftSat(a, shift, .signed, @bitSizeOf(SignedDoubleLimb)); |
| 2053 | try a.shiftLeftSat(&a, shift, .signed, @bitSizeOf(SignedDoubleLimb)); |
| 2054 | 2054 | |
| 2055 | 2055 | try testing.expect((try a.to(SignedDoubleLimb)) == @as(SignedDoubleLimb, x) <<| shift); |
| 2056 | 2056 | } |
| ... | ... | @@ -2061,7 +2061,7 @@ test "big.int sat shift-left signed multi negative" { |
| 2061 | 2061 | |
| 2062 | 2062 | var a = try Managed.initSet(testing.allocator, x); |
| 2063 | 2063 | defer a.deinit(); |
| 2064 | | try a.shiftLeftSat(a, shift, .signed, @bitSizeOf(SignedDoubleLimb)); |
| 2064 | try a.shiftLeftSat(&a, shift, .signed, @bitSizeOf(SignedDoubleLimb)); |
| 2065 | 2065 | |
| 2066 | 2066 | try testing.expect((try a.to(SignedDoubleLimb)) == @as(SignedDoubleLimb, x) <<| shift); |
| 2067 | 2067 | } |
| ... | ... | @@ -2070,7 +2070,7 @@ test "big.int bitNotWrap unsigned simple" { |
| 2070 | 2070 | var a = try Managed.initSet(testing.allocator, 123); |
| 2071 | 2071 | defer a.deinit(); |
| 2072 | 2072 | |
| 2073 | | try a.bitNotWrap(a, .unsigned, 10); |
| 2073 | try a.bitNotWrap(&a, .unsigned, 10); |
| 2074 | 2074 | |
| 2075 | 2075 | try testing.expect((try a.to(u10)) == ~@as(u10, 123)); |
| 2076 | 2076 | } |
| ... | ... | @@ -2079,7 +2079,7 @@ test "big.int bitNotWrap unsigned multi" { |
| 2079 | 2079 | var a = try Managed.initSet(testing.allocator, 0); |
| 2080 | 2080 | defer a.deinit(); |
| 2081 | 2081 | |
| 2082 | | try a.bitNotWrap(a, .unsigned, @bitSizeOf(DoubleLimb)); |
| 2082 | try a.bitNotWrap(&a, .unsigned, @bitSizeOf(DoubleLimb)); |
| 2083 | 2083 | |
| 2084 | 2084 | try testing.expect((try a.to(DoubleLimb)) == maxInt(DoubleLimb)); |
| 2085 | 2085 | } |
| ... | ... | @@ -2088,7 +2088,7 @@ test "big.int bitNotWrap signed simple" { |
| 2088 | 2088 | var a = try Managed.initSet(testing.allocator, -456); |
| 2089 | 2089 | defer a.deinit(); |
| 2090 | 2090 | |
| 2091 | | try a.bitNotWrap(a, .signed, 11); |
| 2091 | try a.bitNotWrap(&a, .signed, 11); |
| 2092 | 2092 | |
| 2093 | 2093 | try testing.expect((try a.to(i11)) == ~@as(i11, -456)); |
| 2094 | 2094 | } |
| ... | ... | @@ -2097,7 +2097,7 @@ test "big.int bitNotWrap signed multi" { |
| 2097 | 2097 | var a = try Managed.initSet(testing.allocator, 0); |
| 2098 | 2098 | defer a.deinit(); |
| 2099 | 2099 | |
| 2100 | | try a.bitNotWrap(a, .signed, @bitSizeOf(SignedDoubleLimb)); |
| 2100 | try a.bitNotWrap(&a, .signed, @bitSizeOf(SignedDoubleLimb)); |
| 2101 | 2101 | |
| 2102 | 2102 | try testing.expect((try a.to(SignedDoubleLimb)) == -1); |
| 2103 | 2103 | } |
| ... | ... | @@ -2108,7 +2108,7 @@ test "big.int bitwise and simple" { |
| 2108 | 2108 | var b = try Managed.initSet(testing.allocator, 0xeeeeeeee22222222); |
| 2109 | 2109 | defer b.deinit(); |
| 2110 | 2110 | |
| 2111 | | try a.bitAnd(a, b); |
| 2111 | try a.bitAnd(&a, &b); |
| 2112 | 2112 | |
| 2113 | 2113 | try testing.expect((try a.to(u64)) == 0xeeeeeeee00000000); |
| 2114 | 2114 | } |
| ... | ... | @@ -2119,7 +2119,7 @@ test "big.int bitwise and multi-limb" { |
| 2119 | 2119 | var b = try Managed.initSet(testing.allocator, maxInt(Limb)); |
| 2120 | 2120 | defer b.deinit(); |
| 2121 | 2121 | |
| 2122 | | try a.bitAnd(a, b); |
| 2122 | try a.bitAnd(&a, &b); |
| 2123 | 2123 | |
| 2124 | 2124 | try testing.expect((try a.to(u128)) == 0); |
| 2125 | 2125 | } |
| ... | ... | @@ -2130,7 +2130,7 @@ test "big.int bitwise and negative-positive simple" { |
| 2130 | 2130 | var b = try Managed.initSet(testing.allocator, 0xeeeeeeee22222222); |
| 2131 | 2131 | defer b.deinit(); |
| 2132 | 2132 | |
| 2133 | | try a.bitAnd(a, b); |
| 2133 | try a.bitAnd(&a, &b); |
| 2134 | 2134 | |
| 2135 | 2135 | try testing.expect((try a.to(u64)) == 0x22222222); |
| 2136 | 2136 | } |
| ... | ... | @@ -2141,7 +2141,7 @@ test "big.int bitwise and negative-positive multi-limb" { |
| 2141 | 2141 | var b = try Managed.initSet(testing.allocator, maxInt(Limb)); |
| 2142 | 2142 | defer b.deinit(); |
| 2143 | 2143 | |
| 2144 | | try a.bitAnd(a, b); |
| 2144 | try a.bitAnd(&a, &b); |
| 2145 | 2145 | |
| 2146 | 2146 | try testing.expect(a.eqZero()); |
| 2147 | 2147 | } |
| ... | ... | @@ -2152,7 +2152,7 @@ test "big.int bitwise and positive-negative simple" { |
| 2152 | 2152 | var b = try Managed.initSet(testing.allocator, -0xeeeeeeee22222222); |
| 2153 | 2153 | defer b.deinit(); |
| 2154 | 2154 | |
| 2155 | | try a.bitAnd(a, b); |
| 2155 | try a.bitAnd(&a, &b); |
| 2156 | 2156 | |
| 2157 | 2157 | try testing.expect((try a.to(u64)) == 0x1111111111111110); |
| 2158 | 2158 | } |
| ... | ... | @@ -2163,7 +2163,7 @@ test "big.int bitwise and positive-negative multi-limb" { |
| 2163 | 2163 | var b = try Managed.initSet(testing.allocator, -maxInt(Limb) - 1); |
| 2164 | 2164 | defer b.deinit(); |
| 2165 | 2165 | |
| 2166 | | try a.bitAnd(a, b); |
| 2166 | try a.bitAnd(&a, &b); |
| 2167 | 2167 | |
| 2168 | 2168 | try testing.expect(a.eqZero()); |
| 2169 | 2169 | } |
| ... | ... | @@ -2174,7 +2174,7 @@ test "big.int bitwise and negative-negative simple" { |
| 2174 | 2174 | var b = try Managed.initSet(testing.allocator, -0xeeeeeeee22222222); |
| 2175 | 2175 | defer b.deinit(); |
| 2176 | 2176 | |
| 2177 | | try a.bitAnd(a, b); |
| 2177 | try a.bitAnd(&a, &b); |
| 2178 | 2178 | |
| 2179 | 2179 | try testing.expect((try a.to(i128)) == -0xffffffff33333332); |
| 2180 | 2180 | } |
| ... | ... | @@ -2185,7 +2185,7 @@ test "big.int bitwise and negative-negative multi-limb" { |
| 2185 | 2185 | var b = try Managed.initSet(testing.allocator, -maxInt(Limb) - 2); |
| 2186 | 2186 | defer b.deinit(); |
| 2187 | 2187 | |
| 2188 | | try a.bitAnd(a, b); |
| 2188 | try a.bitAnd(&a, &b); |
| 2189 | 2189 | |
| 2190 | 2190 | try testing.expect((try a.to(i128)) == -maxInt(Limb) * 2 - 2); |
| 2191 | 2191 | } |
| ... | ... | @@ -2196,7 +2196,7 @@ test "big.int bitwise and negative overflow" { |
| 2196 | 2196 | var b = try Managed.initSet(testing.allocator, -2); |
| 2197 | 2197 | defer b.deinit(); |
| 2198 | 2198 | |
| 2199 | | try a.bitAnd(a, b); |
| 2199 | try a.bitAnd(&a, &b); |
| 2200 | 2200 | |
| 2201 | 2201 | try testing.expect((try a.to(SignedDoubleLimb)) == -maxInt(Limb) - 1); |
| 2202 | 2202 | } |
| ... | ... | @@ -2207,7 +2207,7 @@ test "big.int bitwise xor simple" { |
| 2207 | 2207 | var b = try Managed.initSet(testing.allocator, 0xeeeeeeee22222222); |
| 2208 | 2208 | defer b.deinit(); |
| 2209 | 2209 | |
| 2210 | | try a.bitXor(a, b); |
| 2210 | try a.bitXor(&a, &b); |
| 2211 | 2211 | |
| 2212 | 2212 | try testing.expect((try a.to(u64)) == 0x1111111133333333); |
| 2213 | 2213 | } |
| ... | ... | @@ -2218,7 +2218,7 @@ test "big.int bitwise xor multi-limb" { |
| 2218 | 2218 | var b = try Managed.initSet(testing.allocator, maxInt(Limb)); |
| 2219 | 2219 | defer b.deinit(); |
| 2220 | 2220 | |
| 2221 | | try a.bitXor(a, b); |
| 2221 | try a.bitXor(&a, &b); |
| 2222 | 2222 | |
| 2223 | 2223 | try testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb)); |
| 2224 | 2224 | } |
| ... | ... | @@ -2229,7 +2229,7 @@ test "big.int bitwise xor single negative simple" { |
| 2229 | 2229 | var b = try Managed.initSet(testing.allocator, -0x45fd3acef9191fad); |
| 2230 | 2230 | defer b.deinit(); |
| 2231 | 2231 | |
| 2232 | | try a.bitXor(a, b); |
| 2232 | try a.bitXor(&a, &b); |
| 2233 | 2233 | |
| 2234 | 2234 | try testing.expect((try a.to(i64)) == -0x2efed94fcb932ef9); |
| 2235 | 2235 | } |
| ... | ... | @@ -2240,7 +2240,7 @@ test "big.int bitwise xor single negative zero" { |
| 2240 | 2240 | var b = try Managed.initSet(testing.allocator, -0); |
| 2241 | 2241 | defer b.deinit(); |
| 2242 | 2242 | |
| 2243 | | try a.bitXor(a, b); |
| 2243 | try a.bitXor(&a, &b); |
| 2244 | 2244 | |
| 2245 | 2245 | try testing.expect(a.eqZero()); |
| 2246 | 2246 | } |
| ... | ... | @@ -2251,7 +2251,7 @@ test "big.int bitwise xor single negative multi-limb" { |
| 2251 | 2251 | var b = try Managed.initSet(testing.allocator, 0xf2194e7d1c855272a997fcde16f6d5a8); |
| 2252 | 2252 | defer b.deinit(); |
| 2253 | 2253 | |
| 2254 | | try a.bitXor(a, b); |
| 2254 | try a.bitXor(&a, &b); |
| 2255 | 2255 | |
| 2256 | 2256 | try testing.expect((try a.to(i128)) == -0x6a50889abd8834a24db1f19650d3999a); |
| 2257 | 2257 | } |
| ... | ... | @@ -2262,7 +2262,7 @@ test "big.int bitwise xor single negative overflow" { |
| 2262 | 2262 | var b = try Managed.initSet(testing.allocator, -1); |
| 2263 | 2263 | defer b.deinit(); |
| 2264 | 2264 | |
| 2265 | | try a.bitXor(a, b); |
| 2265 | try a.bitXor(&a, &b); |
| 2266 | 2266 | |
| 2267 | 2267 | try testing.expect((try a.to(SignedDoubleLimb)) == -(maxInt(Limb) + 1)); |
| 2268 | 2268 | } |
| ... | ... | @@ -2273,7 +2273,7 @@ test "big.int bitwise xor double negative simple" { |
| 2273 | 2273 | var b = try Managed.initSet(testing.allocator, -0x4dd4fa576f3046ac); |
| 2274 | 2274 | defer b.deinit(); |
| 2275 | 2275 | |
| 2276 | | try a.bitXor(a, b); |
| 2276 | try a.bitXor(&a, &b); |
| 2277 | 2277 | |
| 2278 | 2278 | try testing.expect((try a.to(u64)) == 0xc39c47081a6eb759); |
| 2279 | 2279 | } |
| ... | ... | @@ -2284,7 +2284,7 @@ test "big.int bitwise xor double negative multi-limb" { |
| 2284 | 2284 | var b = try Managed.initSet(testing.allocator, -0xcb07736a7b62289c78d967c3985eebeb); |
| 2285 | 2285 | defer b.deinit(); |
| 2286 | 2286 | |
| 2287 | | try a.bitXor(a, b); |
| 2287 | try a.bitXor(&a, &b); |
| 2288 | 2288 | |
| 2289 | 2289 | try testing.expect((try a.to(u128)) == 0xa3492ec28e62c410dff92bf0549bf771); |
| 2290 | 2290 | } |
| ... | ... | @@ -2295,7 +2295,7 @@ test "big.int bitwise or simple" { |
| 2295 | 2295 | var b = try Managed.initSet(testing.allocator, 0xeeeeeeee22222222); |
| 2296 | 2296 | defer b.deinit(); |
| 2297 | 2297 | |
| 2298 | | try a.bitOr(a, b); |
| 2298 | try a.bitOr(&a, &b); |
| 2299 | 2299 | |
| 2300 | 2300 | try testing.expect((try a.to(u64)) == 0xffffffff33333333); |
| 2301 | 2301 | } |
| ... | ... | @@ -2306,7 +2306,7 @@ test "big.int bitwise or multi-limb" { |
| 2306 | 2306 | var b = try Managed.initSet(testing.allocator, maxInt(Limb)); |
| 2307 | 2307 | defer b.deinit(); |
| 2308 | 2308 | |
| 2309 | | try a.bitOr(a, b); |
| 2309 | try a.bitOr(&a, &b); |
| 2310 | 2310 | |
| 2311 | 2311 | // TODO: big.int.cpp or is wrong on multi-limb. |
| 2312 | 2312 | try testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb)); |
| ... | ... | @@ -2318,7 +2318,7 @@ test "big.int bitwise or negative-positive simple" { |
| 2318 | 2318 | var b = try Managed.initSet(testing.allocator, 0xeeeeeeee22222222); |
| 2319 | 2319 | defer b.deinit(); |
| 2320 | 2320 | |
| 2321 | | try a.bitOr(a, b); |
| 2321 | try a.bitOr(&a, &b); |
| 2322 | 2322 | |
| 2323 | 2323 | try testing.expect((try a.to(i64)) == -0x1111111111111111); |
| 2324 | 2324 | } |
| ... | ... | @@ -2329,7 +2329,7 @@ test "big.int bitwise or negative-positive multi-limb" { |
| 2329 | 2329 | var b = try Managed.initSet(testing.allocator, 1); |
| 2330 | 2330 | defer b.deinit(); |
| 2331 | 2331 | |
| 2332 | | try a.bitOr(a, b); |
| 2332 | try a.bitOr(&a, &b); |
| 2333 | 2333 | |
| 2334 | 2334 | try testing.expect((try a.to(SignedDoubleLimb)) == -maxInt(Limb)); |
| 2335 | 2335 | } |
| ... | ... | @@ -2340,7 +2340,7 @@ test "big.int bitwise or positive-negative simple" { |
| 2340 | 2340 | var b = try Managed.initSet(testing.allocator, -0xeeeeeeee22222222); |
| 2341 | 2341 | defer b.deinit(); |
| 2342 | 2342 | |
| 2343 | | try a.bitOr(a, b); |
| 2343 | try a.bitOr(&a, &b); |
| 2344 | 2344 | |
| 2345 | 2345 | try testing.expect((try a.to(i64)) == -0x22222221); |
| 2346 | 2346 | } |
| ... | ... | @@ -2351,7 +2351,7 @@ test "big.int bitwise or positive-negative multi-limb" { |
| 2351 | 2351 | var b = try Managed.initSet(testing.allocator, -1); |
| 2352 | 2352 | defer b.deinit(); |
| 2353 | 2353 | |
| 2354 | | try a.bitOr(a, b); |
| 2354 | try a.bitOr(&a, &b); |
| 2355 | 2355 | |
| 2356 | 2356 | try testing.expect((try a.to(SignedDoubleLimb)) == -1); |
| 2357 | 2357 | } |
| ... | ... | @@ -2362,7 +2362,7 @@ test "big.int bitwise or negative-negative simple" { |
| 2362 | 2362 | var b = try Managed.initSet(testing.allocator, -0xeeeeeeee22222222); |
| 2363 | 2363 | defer b.deinit(); |
| 2364 | 2364 | |
| 2365 | | try a.bitOr(a, b); |
| 2365 | try a.bitOr(&a, &b); |
| 2366 | 2366 | |
| 2367 | 2367 | try testing.expect((try a.to(i128)) == -0xeeeeeeee00000001); |
| 2368 | 2368 | } |
| ... | ... | @@ -2373,7 +2373,7 @@ test "big.int bitwise or negative-negative multi-limb" { |
| 2373 | 2373 | var b = try Managed.initSet(testing.allocator, -maxInt(Limb)); |
| 2374 | 2374 | defer b.deinit(); |
| 2375 | 2375 | |
| 2376 | | try a.bitOr(a, b); |
| 2376 | try a.bitOr(&a, &b); |
| 2377 | 2377 | |
| 2378 | 2378 | try testing.expect((try a.to(SignedDoubleLimb)) == -maxInt(Limb)); |
| 2379 | 2379 | } |
| ... | ... | @@ -2384,7 +2384,7 @@ test "big.int var args" { |
| 2384 | 2384 | |
| 2385 | 2385 | var b = try Managed.initSet(testing.allocator, 6); |
| 2386 | 2386 | defer b.deinit(); |
| 2387 | | try a.add(a.toConst(), b.toConst()); |
| 2387 | try a.add(&a, &b); |
| 2388 | 2388 | try testing.expect((try a.to(u64)) == 11); |
| 2389 | 2389 | |
| 2390 | 2390 | var c = try Managed.initSet(testing.allocator, 11); |
| ... | ... | @@ -2404,7 +2404,7 @@ test "big.int gcd non-one small" { |
| 2404 | 2404 | var r = try Managed.init(testing.allocator); |
| 2405 | 2405 | defer r.deinit(); |
| 2406 | 2406 | |
| 2407 | | try r.gcd(a, b); |
| 2407 | try r.gcd(&a, &b); |
| 2408 | 2408 | |
| 2409 | 2409 | try testing.expect((try r.to(u32)) == 1); |
| 2410 | 2410 | } |
| ... | ... | @@ -2417,7 +2417,7 @@ test "big.int gcd non-one small" { |
| 2417 | 2417 | var r = try Managed.init(testing.allocator); |
| 2418 | 2418 | defer r.deinit(); |
| 2419 | 2419 | |
| 2420 | | try r.gcd(a, b); |
| 2420 | try r.gcd(&a, &b); |
| 2421 | 2421 | |
| 2422 | 2422 | try testing.expect((try r.to(u32)) == 38); |
| 2423 | 2423 | } |
| ... | ... | @@ -2430,7 +2430,7 @@ test "big.int gcd non-one large" { |
| 2430 | 2430 | var r = try Managed.init(testing.allocator); |
| 2431 | 2431 | defer r.deinit(); |
| 2432 | 2432 | |
| 2433 | | try r.gcd(a, b); |
| 2433 | try r.gcd(&a, &b); |
| 2434 | 2434 | |
| 2435 | 2435 | try testing.expect((try r.to(u32)) == 4369); |
| 2436 | 2436 | } |
| ... | ... | @@ -2443,7 +2443,7 @@ test "big.int gcd large multi-limb result" { |
| 2443 | 2443 | var r = try Managed.init(testing.allocator); |
| 2444 | 2444 | defer r.deinit(); |
| 2445 | 2445 | |
| 2446 | | try r.gcd(a, b); |
| 2446 | try r.gcd(&a, &b); |
| 2447 | 2447 | |
| 2448 | 2448 | const answer = (try r.to(u256)); |
| 2449 | 2449 | try testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1); |
| ... | ... | @@ -2457,7 +2457,7 @@ test "big.int gcd one large" { |
| 2457 | 2457 | var r = try Managed.init(testing.allocator); |
| 2458 | 2458 | defer r.deinit(); |
| 2459 | 2459 | |
| 2460 | | try r.gcd(a, b); |
| 2460 | try r.gcd(&a, &b); |
| 2461 | 2461 | |
| 2462 | 2462 | try testing.expect((try r.to(u64)) == 1); |
| 2463 | 2463 | } |
| ... | ... | @@ -2488,10 +2488,10 @@ test "big.int pow" { |
| 2488 | 2488 | var a = try Managed.initSet(testing.allocator, -3); |
| 2489 | 2489 | defer a.deinit(); |
| 2490 | 2490 | |
| 2491 | | try a.pow(a.toConst(), 3); |
| 2491 | try a.pow(&a, 3); |
| 2492 | 2492 | try testing.expectEqual(@as(i32, -27), try a.to(i32)); |
| 2493 | 2493 | |
| 2494 | | try a.pow(a.toConst(), 4); |
| 2494 | try a.pow(&a, 4); |
| 2495 | 2495 | try testing.expectEqual(@as(i32, 531441), try a.to(i32)); |
| 2496 | 2496 | } |
| 2497 | 2497 | { |
| ... | ... | @@ -2502,9 +2502,9 @@ test "big.int pow" { |
| 2502 | 2502 | defer y.deinit(); |
| 2503 | 2503 | |
| 2504 | 2504 | // y and a are not aliased |
| 2505 | | try y.pow(a.toConst(), 123); |
| 2505 | try y.pow(&a, 123); |
| 2506 | 2506 | // y and a are aliased |
| 2507 | | try a.pow(a.toConst(), 123); |
| 2507 | try a.pow(&a, 123); |
| 2508 | 2508 | |
| 2509 | 2509 | try testing.expect(a.eq(y)); |
| 2510 | 2510 | |
| ... | ... | @@ -2522,18 +2522,18 @@ test "big.int pow" { |
| 2522 | 2522 | var a = try Managed.initSet(testing.allocator, 0); |
| 2523 | 2523 | defer a.deinit(); |
| 2524 | 2524 | |
| 2525 | | try a.pow(a.toConst(), 100); |
| 2525 | try a.pow(&a, 100); |
| 2526 | 2526 | try testing.expectEqual(@as(i32, 0), try a.to(i32)); |
| 2527 | 2527 | |
| 2528 | 2528 | try a.set(1); |
| 2529 | | try a.pow(a.toConst(), 0); |
| 2529 | try a.pow(&a, 0); |
| 2530 | 2530 | try testing.expectEqual(@as(i32, 1), try a.to(i32)); |
| 2531 | | try a.pow(a.toConst(), 100); |
| 2531 | try a.pow(&a, 100); |
| 2532 | 2532 | try testing.expectEqual(@as(i32, 1), try a.to(i32)); |
| 2533 | 2533 | try a.set(-1); |
| 2534 | | try a.pow(a.toConst(), 15); |
| 2534 | try a.pow(&a, 15); |
| 2535 | 2535 | try testing.expectEqual(@as(i32, -1), try a.to(i32)); |
| 2536 | | try a.pow(a.toConst(), 16); |
| 2536 | try a.pow(&a, 16); |
| 2537 | 2537 | try testing.expectEqual(@as(i32, 1), try a.to(i32)); |
| 2538 | 2538 | } |
| 2539 | 2539 | } |
| ... | ... | @@ -2547,7 +2547,7 @@ test "big.int regression test for 1 limb overflow with alias" { |
| 2547 | 2547 | defer b.deinit(); |
| 2548 | 2548 | |
| 2549 | 2549 | try a.ensureAddCapacity(a.toConst(), b.toConst()); |
| 2550 | | try a.add(a.toConst(), b.toConst()); |
| 2550 | try a.add(&a, &b); |
| 2551 | 2551 | |
| 2552 | 2552 | try testing.expect(a.toConst().orderAgainstScalar(19740274219868223167) == .eq); |
| 2553 | 2553 | } |
| ... | ... | @@ -2561,7 +2561,7 @@ test "big.int regression test for realloc with alias" { |
| 2561 | 2561 | defer b.deinit(); |
| 2562 | 2562 | |
| 2563 | 2563 | try a.ensureAddCapacity(a.toConst(), b.toConst()); |
| 2564 | | try a.add(a.toConst(), b.toConst()); |
| 2564 | try a.add(&a, &b); |
| 2565 | 2565 | |
| 2566 | 2566 | try testing.expect(a.toConst().orderAgainstScalar(14691098406862188148944207245954912110548093601382197697835) == .eq); |
| 2567 | 2567 | } |
| ... | ... | @@ -2572,7 +2572,7 @@ test "big int popcount" { |
| 2572 | 2572 | var b = try Managed.initSet(testing.allocator, -1); |
| 2573 | 2573 | defer b.deinit(); |
| 2574 | 2574 | |
| 2575 | | try a.popCount(b.toConst(), 16); |
| 2575 | try a.popCount(&b, 16); |
| 2576 | 2576 | |
| 2577 | 2577 | try testing.expect(a.toConst().orderAgainstScalar(16) == .eq); |
| 2578 | 2578 | } |