1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const { create, all, factory } = require('../..')
|
7 | const math = create(all)
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | math.import([
|
13 | factory('BigInt', ['typed'], function createBigInt ({ typed }) {
|
14 | typed.addType({
|
15 | name: 'BigInt',
|
16 | test: (x) => typeof x === 'bigint'
|
17 | })
|
18 |
|
19 | return BigInt
|
20 | }, { lazy: false }),
|
21 |
|
22 | factory('bigint', ['typed', 'BigInt'], function createBigint ({ typed, BigInt }) {
|
23 | return typed('bigint', {
|
24 | 'number | string ': (x) => BigInt(x)
|
25 | })
|
26 | }),
|
27 |
|
28 | factory('add', ['typed'], function createBigIntAdd ({ typed }) {
|
29 | return typed('add', {
|
30 | 'BigInt, BigInt': (a, b) => a + b
|
31 | })
|
32 | }),
|
33 |
|
34 | factory('pow', ['typed'], function createBigIntPow ({ typed }) {
|
35 | return typed('pow', {
|
36 | 'BigInt, BigInt': (a, b) => a ** b
|
37 | })
|
38 | })
|
39 | ])
|
40 |
|
41 | console.log(math.evaluate('4349 + 5249'))
|
42 | console.log(math.evaluate('bigint(4349) + bigint(5249)'))
|
43 | console.log(math.evaluate('bigint(4349) ^ bigint(5249)'))
|