Rational approximation with bounded denominator
Want to see pretty graphs? Log in now!
npm install frac
|9||downloads in the last day|
|420||downloads in the last week|
|2 013||downloads in the last month|
|Last Published By|
|Version||0.3.1 last updated 3 months ago|
|Keywords||math, fraction, rational, approximation|
Rational approximation to a floating point number with bounded denominator.
Uses the Mediant Method https://en.wikipedia.org/wiki/Mediant_(mathematics)
This module also provides an implementation of the continued fraction method as described by Aberth in "A method for exact computation with rational numbers", which appears to be used by spreadsheet programs for displaying fractions
JS Installation and Usage
$ npm install frac
In the browser:
frac function takes three arguments:
xthe number we wish to approximate
Dthe maximum denominator
mixedif true, return a mixed fraction (default); if false, improper
The return value is an array of the form
[quot, num, den] where
for improper fractions.
> // 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 ]
frac.cont implements the Aberth algorithm (input and output specifications
match the original
Tests generated from Excel have 4 columns. To produce a similar test:
- Column A contains the raw values
- Column B format "Up to one digit (1/4)"
- Column C format "Up to two digits (21/25)"
- Column D format "Up to three digits (312/943)"