-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
143 changed files
with
1,570 additions
and
262 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
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,54 @@ | ||
# BigInts | ||
|
||
For calculations with large integer numbers, math.js supports the built-in `bigint` data type. | ||
|
||
## Usage | ||
|
||
A bigint can be created either by adding the suffix `n` to a `number`, using the `BigInt` constructor function, or using the util function `math.bigint`: | ||
|
||
```js | ||
42n | ||
BigInt('42') | ||
math.bigint('42') | ||
``` | ||
|
||
Most functions can determine the type of output from the type of input: | ||
a `number` as input will return a `number` as output, a `bigint` as input returns | ||
a `bigint` as output. Functions which cannot determine the type of output | ||
from the input (for example `math.evaluate`) use the default number type `number`, | ||
which can be configured when instantiating math.js. To configure the use of | ||
`bigint` instead of [numbers](numbers.md) by default, configure math.js like: | ||
|
||
```js | ||
math.config({ | ||
number: 'bigint' | ||
}) | ||
|
||
// use math | ||
math.evaluate('70000000000000000123') // bigint 70000000000000000123n | ||
``` | ||
|
||
## Support | ||
|
||
All basic arithmetic functions in math.js support `bigint`. Since `bigint` can only hold integer values, it is not applicable to for example trigonometric functions. When using a `bigint` in a function that does not support it, like `sqrt`, it will convert the `bigint` into a regular `number` and then execute the function: | ||
|
||
```js | ||
math.sin(2n) // number 0.9092974268256817 | ||
``` | ||
|
||
## Conversion | ||
|
||
There are utility functions to convert a `bigint` into a `number` or `BigNumber`: | ||
|
||
```js | ||
// convert a number to bigint or BigNumber | ||
math.bigint(42) // bigint, 42n | ||
math.bignumber(42) // BigNumber, 42 | ||
|
||
// convert a bigint to a number or BigNumber | ||
math.number(42n) // number, 42 | ||
math.bignumber(42n) // BigNumber, 42 | ||
|
||
// losing digits when converting to number | ||
math.number(70000000000000000123n) // number, 7000000000000000000 | ||
``` |
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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ export { | |
isArrayNode, | ||
isAssignmentNode, | ||
isBigNumber, | ||
isBigInt, | ||
isBlockNode, | ||
isBoolean, | ||
isChain, | ||
|
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,17 @@ | ||
export const bigintDocs = { | ||
name: 'bigint', | ||
category: 'Construction', | ||
syntax: [ | ||
'bigint(x)' | ||
], | ||
description: | ||
'Create a bigint, an integer with an arbitrary number of digits, from a number or string.', | ||
examples: [ | ||
'123123123123123123 # a large number will lose digits', | ||
'bigint("123123123123123123")', | ||
'bignumber(["1", "3", "5"])' | ||
], | ||
seealso: [ | ||
'boolean', 'bignumber', 'number', 'complex', 'fraction', 'index', 'matrix', 'string', 'unit' | ||
] | ||
} |
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
Oops, something went wrong.