Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial commit
  • Loading branch information
kenany committed Sep 8, 2013
0 parents commit 5d4829a
Show file tree
Hide file tree
Showing 8 changed files with 2,276 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
* text=auto
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
18 changes: 18 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,18 @@
Copyright 2013 Kenan Yildirim <http://kenany.me/>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48 changes: 48 additions & 0 deletions README.md
@@ -0,0 +1,48 @@
# big-factorial

Like [factorial](https://github.com/wearefractal/factorial) but for big numbers.
Inspired by
[a blog post](http://raganwald.com/2013/03/28/trampolines-in-javascript.html) by
Reginald Braithwaite ([@raganwald](https://github.com/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:

``` javascript
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](https://github.com/peterolson/BigInteger.js).

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

``` bash
$ npm install big-factorial
```

## API

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

### bigFactorial(value)

Returns the factorial of `value`.

0 comments on commit 5d4829a

Please sign in to comment.