Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// This example demonstrates how you could integrate support for BigInt | ||
// in mathjs. It's just a proof of concept, for full support you will | ||
// have to defined more functions and define conversions from and to | ||
// other data types. | ||
|
||
const math = require('../../index') | ||
|
||
math.import({ | ||
name: 'BigInt', | ||
path: 'type', // will be imported into math.type.BigInt | ||
factory: (type, config, load, typed) => { | ||
typed.addType({ | ||
name: 'BigInt', | ||
test: (x) => typeof x === 'bigint' // eslint-disable-line | ||
}) | ||
|
||
// we can also add conversions here from number or string to BigInt | ||
// and vice versa using typed.addConversion(...) | ||
|
||
return BigInt // eslint-disable-line | ||
}, | ||
|
||
// disable lazy loading as this factory has side | ||
// effects: it adds a type and a conversion. | ||
lazy: false | ||
}) | ||
|
||
math.import({ | ||
name: 'bigint', | ||
factory: (type, config, load, typed) => { | ||
return typed('bigint', { | ||
'number | string ': (x) => BigInt(x) // eslint-disable-line | ||
}) | ||
} | ||
}) | ||
|
||
math.import({ | ||
name: 'add', | ||
factory: (type, config, load, typed) => { | ||
return typed('add', { | ||
'BigInt, BigInt': (a, b) => a + b | ||
}) | ||
} | ||
}) | ||
|
||
math.import({ | ||
name: 'pow', | ||
factory: (type, config, load, typed) => { | ||
return typed('pow', { | ||
'BigInt, BigInt': (a, b) => a ** b | ||
}) | ||
} | ||
}) | ||
|
||
console.log(math.eval('bigint(4349) + bigint(5249)')) | ||
console.log(math.eval('bigint(4349) ^ bigint(5249)')) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = '5.1.2' | ||
module.exports = '5.2.0' | ||
// Note: This file is automatically generated when building math.js. | ||
// Changes made in this file will be overwritten. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters