Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

big-factorial

kenany4MIT3.0.1

Calculate the factorial of big numbers.

math

readme

big-factorial

Like factorial but for big numbers. Inspired by a blog post by Reginald Braithwaite (@raganwald).

Example

If you want to find the factorial of an integer less than 171, then you don't need this module. Otherwise, you do need it:

var factorial = require('factorial');

factorial(170);
// => 7.257415615307994e+306

factorial(171);
// => Infinity

factorial(32768);
// => RangeError: Maximum call stack size exceeded

The Infinity problem is a result of JavaScript's limit on how big numbers can be. This module solves this problem by using big-integer.

The RangeError is a problem with how the factorial is calculated. The recursion used goes so deep that it exceeds the limit that Node.js has. As described in Reginald's blog post, this problem is solved by using trampolines.

Installation

$ npm install big-factorial

API

var bigFactorial = require('big-factorial');

bigFactorial(value)

Returns the factorial of value as a bigInt, where value is either a Number or a String.

changelog

3.0.1 (2023-12-13)

Bug Fixes

3.0.0 (2023-09-17)

⚠ BREAKING CHANGES

  • Node.js v14 and v16 are no longer supported.

Features

  • drop Node.js v14 and v16 (5065cbe)

2.0.0 (2022-12-22)

⚠ BREAKING CHANGES

  • Node.js v12 is no longer supported.

Features

  • drop Node.js v12 support (337c31d)

1.0.6 (2021-11-11)

Bug Fixes

1.0.5 (2021-10-19)

Bug Fixes

1.0.4 (2021-09-19)

Bug Fixes

1.0.3 (2021-03-30)

Bug Fixes