Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Calculate the factorial of big numbers.
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test
.gitattributes
.gitignore
.travis.yml
LICENSE.txt
README.md
index.js
package.json

README.md

big-factorial

Build Status Dependency Status

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.

Something went wrong with that request. Please try again.