Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tom-weatherhead/number-theory-js
A library of JavaScript implementations of number theory utilities.
https://github.com/tom-weatherhead/number-theory-js
math mathematics number-theory prime-factors prime-numbers
Last synced: about 7 hours ago
JSON representation
A library of JavaScript implementations of number theory utilities.
- Host: GitHub
- URL: https://github.com/tom-weatherhead/number-theory-js
- Owner: tom-weatherhead
- License: mit
- Created: 2018-05-24T02:18:19.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T15:16:00.000Z (almost 2 years ago)
- Last Synced: 2024-04-14T23:52:50.853Z (7 months ago)
- Topics: math, mathematics, number-theory, prime-factors, prime-numbers
- Language: JavaScript
- Homepage:
- Size: 1.3 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# number-theory-js
[![build status](https://secure.travis-ci.org/tom-weatherhead/number-theory-js.svg)](http://travis-ci.org/tom-weatherhead/number-theory-js)
number-theory-js is a library of JavaScript implementations of number theory utilities.
Most of this project's infrastructure was stolen from Jason Mulligan's ([avoidwork](https://github.com/avoidwork)'s) [tiny-graph](http://avoidwork.github.io/tiny-graph) project.
## Example
```javascript
const engine = require('number-theory-js');console.log(engine.factorize(72)); // [2, 2, 2, 3, 3]
console.log(engine.gcd(35, 84)); // 7
console.log(engine.sieve(20)); // [2, 3, 5, 7, 11, 13, 17, 19]
```## How can I use number-theory-js?
number-theory-js can be installed from npm and bower, and supports AMD loaders or script tags (e.g. `window.sieve`).## API
#### gcd(m, n)
Returns the greatest common divisor of integers `m` and `n`, calculated using Euclid's algorithm#### factorize(n)
Returns the unique prime factorization of `n` as a list of integers#### sieve(n)
Returns the list of all prime numbers less than `n`, calculated using the Sieve of Eratosthenes#### totient(n)
Euler's totient function: Returns the list of all positive integers less than `n` that are relatively prime to `n`## License
Copyright (c) 2018 Tom Weatherhead
Licensed under the MIT license