1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const math = require('../../index')
|
7 |
|
8 | math.import({
|
9 | name: 'BigInt',
|
10 | path: 'type',
|
11 | factory: (type, config, load, typed) => {
|
12 | typed.addType({
|
13 | name: 'BigInt',
|
14 | test: (x) => typeof x === 'bigint'
|
15 | })
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | return BigInt
|
21 | },
|
22 |
|
23 |
|
24 |
|
25 | lazy: false
|
26 | })
|
27 |
|
28 | math.import({
|
29 | name: 'bigint',
|
30 | factory: (type, config, load, typed) => {
|
31 | return typed('bigint', {
|
32 | 'number | string ': (x) => BigInt(x)
|
33 | })
|
34 | }
|
35 | })
|
36 |
|
37 | math.import({
|
38 | name: 'add',
|
39 | factory: (type, config, load, typed) => {
|
40 | return typed('add', {
|
41 | 'BigInt, BigInt': (a, b) => a + b
|
42 | })
|
43 | }
|
44 | })
|
45 |
|
46 | math.import({
|
47 | name: 'pow',
|
48 | factory: (type, config, load, typed) => {
|
49 | return typed('pow', {
|
50 | 'BigInt, BigInt': (a, b) => a ** b
|
51 | })
|
52 | }
|
53 | })
|
54 |
|
55 | console.log(math.eval('bigint(4349) + bigint(5249)'))
|
56 | console.log(math.eval('bigint(4349) ^ bigint(5249)'))
|