Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xuandieu1210 committed Feb 27, 2024
0 parents commit 70cb55d
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
7 changes: 7 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>kenany/renovate-config",
":assignAndReview(kenany)"
]
}
26 changes: 26 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: nodejs
on: [pull_request, push]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [18, 20]
os: [ubuntu-latest]
steps:
- name: Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4.0.0
with:
node-version: ${{ matrix.node-version }}
- name: Update npm
run: |
npm install -g npm
npm --version
- uses: actions/checkout@v4.1.1
- name: Install dependencies
uses: bahmutov/npm-install@v1.8.36
with:
useLockFile: false
- run: npm ls
- name: Test
run: npm test
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: release
on:
push:
branches:
- master
permissions:
contents: read
jobs:
release:
name: release
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
issues: write
pull-requests: write
steps:
- uses: actions/setup-node@v4.0.0
with:
node-version: 20
- name: Update npm
run: |
npm install -g npm
npm --version
- uses: actions/checkout@v4.1.1
- name: Install dependencies
uses: bahmutov/npm-install@v1.8.36
with:
useLockFile: false
- run: npm audit signatures
- name: Release
run: npm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
12 changes: 12 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/github",
"@semantic-release/npm",
"@semantic-release/git"
],
"preset": "conventionalcommits",
"tagFormat": "${version}"
}
56 changes: 56 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## [3.0.1](https://github.com/kenany/big-factorial/compare/3.0.0...3.0.1) (2023-12-13)


### Bug Fixes

* **deps:** big-integer@1.6.52 ([8be0781](https://github.com/kenany/big-factorial/commit/8be0781b42f390ce56f8f502fe77e5bfd5bac17b))

## [3.0.0](https://github.com/kenany/big-factorial/compare/2.0.0...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](https://github.com/kenany/big-factorial/commit/5065cbefbb3ad13d3969c1f7d56339a442fc0437))

## [2.0.0](https://github.com/KenanY/big-factorial/compare/1.0.6...2.0.0) (2022-12-22)


### ⚠ BREAKING CHANGES

* Node.js v12 is no longer supported.

### Features

* drop Node.js v12 support ([337c31d](https://github.com/KenanY/big-factorial/commit/337c31db5b472a901193b9867ee062074bbdaaae))

### [1.0.6](https://github.com/KenanY/big-factorial/compare/1.0.5...1.0.6) (2021-11-11)


### Bug Fixes

* **deps:** big-integer@1.6.51 ([94a8f0e](https://github.com/KenanY/big-factorial/commit/94a8f0e8e3304b4d09d63a406e388738908a30c7))

### [1.0.5](https://github.com/KenanY/big-factorial/compare/1.0.4...1.0.5) (2021-10-19)


### Bug Fixes

* **deps:** big-integer@1.6.50 ([0c9ea9c](https://github.com/KenanY/big-factorial/commit/0c9ea9cdb3f170f5284a4a6d33a5fc96022bf1d3))

### [1.0.4](https://github.com/KenanY/big-factorial/compare/1.0.3...1.0.4) (2021-09-19)


### Bug Fixes

* **deps:** big-integer@1.6.49 ([d8d1187](https://github.com/KenanY/big-factorial/commit/d8d1187e89a24f25fd8a7a5eb5c417674d86594d))

### [1.0.3](https://github.com/KenanY/big-factorial/compare/1.0.2...1.0.3) (2021-03-30)


### Bug Fixes

* **deps:** big-integer@1.6.48 ([492af05](https://github.com/KenanY/big-factorial/commit/492af0545c3d0ca95ca3dc0dec58beedb31ffc63))
18 changes: 18 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright 2013–2023 Kenan Yildirim <https://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.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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

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

### bigFactorial(value)

Returns the factorial of `value` as a _bigInt_, where `value` is either a
_Number_ or a _String_.
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var bilby = require('bilby');
var bigInt = require('big-integer');

function _factorial(acc, n) {
return n.greater(0)
? bilby.cont(function() { return _factorial(acc.times(n), n.minus(1)); })
: bilby.done(acc);
}

function factorial(value) {
return bilby.trampoline(_factorial(bigInt.one, bigInt(value)));
}

module.exports = factorial;
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "deo-big-factorial",
"version": "1.0.0",
"description": "my package",
"main": "index.js",
"directories": {
"test": "test"
},
"dependencies": {
"deo-vector-math": "^1.0.0",
"deotheme": "^1.0.1"
},
"scripts": {
"test": "test"
},
"author": "xuandieu1210",
"license": "ISC"
}
10 changes: 10 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const factorial = require('../');
const test = require('tape');

test('big-factorial', (t) => {
t.plan(3);

t.equal(factorial(0).toString(), '1');
t.equal(factorial(10).toString(), '3628800');
t.equal(factorial(21).toString(), '51090942171709440000');
});

0 comments on commit 70cb55d

Please sign in to comment.