-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.hbs
66 lines (44 loc) · 2.22 KB
/
template.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# bigint-factorial
![npm](https://img.shields.io/npm/v/bigint-factorial)
![npm bundle size](https://img.shields.io/bundlephobia/min/bigint-factorial)
![David](https://img.shields.io/david/polarstoat/bigint-factorial)
![GitHub](https://img.shields.io/github/license/polarstoat/bigint-factorial)
> Tiny factorial function using JavaScript's built-in [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
Factorials get very big, very quickly. Older packages for calculating them that use the `number` primitive internally suffer the following issues:
- **Subject to imprecision at factorials larger than 18** (at which point they surpass `Number.MAX_SAFE_INTEGER`)
- **Return `Infinity` at factorials larger than 170** (at which point they surpass `Number.MAX_VALUE`)
This package avoids these by dealing exclusively with the `bigint` primitive.
## Install
Install with [npm](https://www.npmjs.com/package/bigint-factorial) (or [Yarn](https://yarnpkg.com/package/bigint-factorial))
```sh
npm i bigint-factorial
```
## Usage
1. Import the package
```js
import factorial from 'bigint-factorial';
// or
const factorial = require('bigint-factorial');
```
2. Calculate factorials
```js
factorial(5n);
// ↪︎ 120n
factorial(6n);
// ↪︎ 720n
factorial(7n);
// ↪︎ 5040n
factorial(183n);
// ↪︎ 1211079010624906224171770242040000913194755344907123328387229208384122199143398983962077168073033852647945203036376445283346314711222230177466494273255728793463071956674839497876987299889729720327479783667584731115257659422804284707863129430806869565563037239578516564219715854442393339376435200000000000000000000000000000000000000000000n
```
## API
{{#module name="factorial"}}
<a name="{{{anchorName}}}"></a>
### {{>sig-name}}
{{>body}}
{{/module}}
## System requirements
- [Node.js](https://nodejs.org/en/) `v10.24.1`
- [npm](https://www.npmjs.com) `v6.14.12`
This package has been tested and confirmed to work on the above versions.
BigInt was [added to Node.js in `v10.4.0`](https://nodejs.org/en/blog/release/v10.4.0/) with [V8 release `v6.7`](https://v8.dev/blog/v8-release-67), therefore this package won't work in Node.js versions earlier than `v10.4.0`.