@@ -3,11 +3,13 @@ import { BigInt } from 'as-bigint/assembly/BigInt';
33
44const a = '0xFEEBDAEDFEEBDAEDFEEBDAEDFEEBDAEDFEEBDAEDFEEBDAEDFEEBDAEDFEEBDAED' ;
55const b = '0x0000DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEAD' ;
6- const mpzA = blackbox ( MpZ . from ( a ) ) ;
7- const mpzB = blackbox ( MpZ . from ( b ) ) ;
6+ const mpzA = MpZ . from ( a ) ;
7+ const mpzB = MpZ . from ( b ) ;
88
9- const bigIntA = blackbox ( BigInt . from ( a ) ) ;
10- const bigIntB = blackbox ( BigInt . from ( b ) ) ;
9+ const bigIntA = BigInt . from ( a ) ;
10+ const bigIntB = BigInt . from ( b ) ;
11+
12+ assert ( `${ mpzA . div ( mpzB ) } ` === `${ bigIntA . div ( bigIntB ) } ` ) ;
1113
1214suite ( 'div large' , ( ) => {
1315 bench ( 'MpZ#_udiv (large)' , ( ) => {
@@ -25,8 +27,10 @@ suite('div large', () => {
2527} ) ;
2628
2729const c = '0xDEAD' ;
28- const mpzC = blackbox ( MpZ . from ( c ) ) ;
29- const bigIntC = blackbox ( BigInt . from ( c ) ) ;
30+ const mpzC = MpZ . from ( c ) ;
31+ const bigIntC = BigInt . from ( c ) ;
32+
33+ assert ( `${ mpzA . div ( mpzC ) } ` === `${ bigIntA . div ( bigIntC ) } ` ) ;
3034
3135suite ( 'div small' , ( ) => {
3236 bench ( 'MpZ#_udiv (small)' , ( ) => {
@@ -42,3 +46,30 @@ suite('div small', () => {
4246 blackbox ( bigIntA . div ( bigIntC ) ) ;
4347 } ) ;
4448} ) ;
49+
50+ function fact < T > ( one : T , n : T ) : T {
51+ let a = one ;
52+ while ( n > one ) {
53+ a *= n ;
54+ n -= one ;
55+ }
56+ return a ;
57+ }
58+
59+ const f1 = fact < MpZ > ( MpZ . from ( 1 ) , MpZ . from ( 1000 ) ) ;
60+ const f2 = fact < MpZ > ( MpZ . from ( 1 ) , MpZ . from ( 500 ) ) ;
61+
62+ const f3 = fact ( BigInt . from ( 1 ) , BigInt . from ( 1000 ) ) ;
63+ const f4 = fact ( BigInt . from ( 1 ) , BigInt . from ( 500 ) ) ;
64+
65+ assert ( `${ f3 / f4 } ` === `${ f1 / f2 } ` ) ;
66+
67+ suite ( 'mul very large' , ( ) => {
68+ bench ( 'MpZ#mul (very large)' , ( ) => {
69+ blackbox ( f1 . mul ( f2 ) ) ;
70+ } ) ;
71+
72+ bench ( 'BigInt#mul (very large)' , ( ) => {
73+ blackbox ( f3 . mul ( f4 ) ) ;
74+ } ) ;
75+ } ) ;
0 commit comments