rational approximation with bounded denominator
Go to file
2013-12-14 02:11:37 -05:00
.travis.yml Initial commit 2013-12-14 02:11:37 -05:00
frac.js Initial commit 2013-12-14 02:11:37 -05:00
frac.md Initial commit 2013-12-14 02:11:37 -05:00
LICENSE Initial commit 2013-12-14 02:11:37 -05:00
Makefile Initial commit 2013-12-14 02:11:37 -05:00
package.json Initial commit 2013-12-14 02:11:37 -05:00
README.md Initial commit 2013-12-14 02:11:37 -05:00
test.js Initial commit 2013-12-14 02:11:37 -05:00

frac

Rational approximation to a floating point number with bounded denominator.

Uses the Mediant Method https://en.wikipedia.org/wiki/Mediant_(mathematics)

JS Installation and Usage

In node:

$ npm install frac

In the browser:

<script src="frac.js"></script>

The exported frac function takes three arguments:

  • x the number we wish to approximate
  • D the maximum denominator
  • mixed if true, return a mixed fraction (default); if false, improper

The return value is an array of the form [quot, num, den] where quot==0 for improper fractions.

For example:

> // var frac = require('frac'); // uncomment this line if in node
> frac(Math.PI,100) // [ 0, 22, 7 ]
> frac(Math.PI,100,true) // [ 3, 1, 7 ]