Skip to content

Commit 0359fda

Browse files
🔍 test: Define ALU based on bn.js.
1 parent 3db9cfd commit 0359fda

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@babel/preset-env": "7.9.6",
3737
"@babel/register": "7.9.0",
3838
"ava": "3.8.1",
39+
"bn.js": "^5.1.1",
3940
"coveralls": "3.1.0",
4041
"esdoc": "1.1.0",
4142
"esdoc-inject-script-plugin": "1.0.0",

test/src/core.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import test from 'ava';
22
import { _add , _sub , _mul , _div , _cmp , _cmp_no_bounds , _simplify } from '../../src';
33

44
import int from 'int' ;
5+
import BN from 'bn.js' ;
56
import { ZZ } from '@aureooms/js-integer' ;
67

78
const GOOGOL = '10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ;
@@ -63,6 +64,28 @@ const ALU = [
6364
sgn : x => x.cmp(0),
6465
divmod : (a,b) => [a.div(b), a.mod(b)],
6566
},
67+
{
68+
name : 'bn.js',
69+
add : (a, b) => a.add(b),
70+
sub : (a, b) => a.sub(b),
71+
mul : (a, b) => a.mul(b),
72+
div : (a, b) => a.div(b),
73+
reg : x => new BN(x),
74+
str : x => x.toString(),
75+
jz : x => x.eqn(0),
76+
lt0 : x => x.ltn(0),
77+
cmp : (a,b) => a.cmp(b),
78+
sgn : x => x.cmpn(0),
79+
neg : x => x.neg(),
80+
divmod : (a,b) => {
81+
const { div , mod } = a.divmod(b) ;
82+
return [div, mod] ;
83+
} ,
84+
egcd : (a,b) => {
85+
const gcd = a.gcd(b) ;
86+
return { u: b.div(gcd), v: a.div(gcd) } ;
87+
} ,
88+
},
6689
{
6790
name : '@aureooms/js-integer',
6891
add : (a, b) => a.add(b),

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,11 @@ blueimp-md5@^2.10.0:
13551355
resolved "https://registry.yarnpkg.com/blueimp-md5/-/blueimp-md5-2.13.0.tgz#07314b0c64dda0bf1733f96ce40d5af94eb28965"
13561356
integrity sha512-lmp0m647R5e77ORduxLW5mISIDcvgJZa52vMBv5uVI3UmSWTQjkJsZVBfaFqQPw/QFogJwvY6e3Gl9nP+Loe+Q==
13571357

1358+
bn.js@^5.1.1:
1359+
version "5.1.1"
1360+
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.1.tgz#48efc4031a9c4041b9c99c6941d903463ab62eb5"
1361+
integrity sha512-IUTD/REb78Z2eodka1QZyyEk66pciRcP6Sroka0aI3tG/iwIdYLrBD62RsubR7vqdt3WyX8p4jxeatzmRSphtA==
1362+
13581363
boolbase@~1.0.0:
13591364
version "1.0.0"
13601365
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"

0 commit comments

Comments
 (0)