Gathering detailed insights and metrics for frac
Gathering detailed insights and metrics for frac
Gathering detailed insights and metrics for frac
Gathering detailed insights and metrics for frac
npm install frac
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.8
Supply Chain
100
Quality
75.7
Maintenance
100
Vulnerability
100
License
JavaScript (90.1%)
Python (2.65%)
CSS (2.56%)
HTML (1.81%)
Makefile (1.75%)
Shell (0.95%)
TypeScript (0.18%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
72 Stars
20 Commits
5 Forks
6 Watchers
2 Branches
3 Contributors
Updated on May 01, 2024
Latest Version
1.1.2
Package Id
frac@1.1.2
Size
4.52 kB
NPM Version
5.6.0
Node Version
8.9.4
Published on
Feb 20, 2018
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Rational approximation to a floating point number with bounded denominator.
Uses the Mediant Method.
This module also provides an implementation of the continued fraction method as described by Aberth in "A method for exact computation with rational numbers". The algorithm is used in SheetJS Libraries to replicate fraction formats.
With npm
:
1$ npm install frac
In the browser:
1<script src="frac.js"></script>
The script will manipulate module.exports
if available . This is not always
desirable. To prevent the behavior, define DO_NOT_EXPORT_FRAC
From PyPI
:
1$ pip install frac
In all cases, the relevant function takes 3 arguments:
x
the number we wish to approximateD
the maximum denominatormixed
if true, return a mixed fraction; if false, improperThe return value is an array of the form [quot, num, den]
where quot==0
for improper fractions. quot <= x
for mixed fractions, which may lead to some
unexpected results when rendering negative numbers.
The exported frac
function implements the Mediant method.
frac.cont
implements the Aberth algorithm
For example:
1> // var frac = require('frac'); // uncomment this line if in node 2> frac(1.3, 9); // [ 0, 9, 7 ] // 1.3 ~ 9/7 3> frac(1.3, 9, true); // [ 1, 2, 7 ] // 1.3 ~ 1 + 2/7 4> frac(-1.3, 9); // [ 0, -9, 7 ] // -1.3 ~ -9/7 5> frac(-1.3, 9, true); // [ -2, 5, 7 ] // -1.3 ~ -2 + 5/7 6 7> frac.cont(1.3, 9); // [ 0, 4, 3 ] // 1.3 ~ 4/3 8> frac.cont(1.3, 9, true); // [ 1, 1, 3 ] // 1.3 ~ 1 + 1/3 9> frac.cont(-1.3, 9); // [ 0, -4, 3 ] // -1.3 ~ -4/3 10> frac.cont(-1.3, 9, true); // [ -2, 2, 3 ] // -1.3 ~ -2 + 2/3
frac.med
implements Mediant method.
frac.cont
implements Aberth algorithm.
For example:
1>>> import frac 2>>> frac.med(1.3, 9) ## [ 0, 9, 7 ] ## 1.3 ~ 9/7 3>>> frac.med(1.3, 9, True) ## [ 1, 2, 7 ] ## 1.3 ~ 1 + 2/7 4>>> frac.med(-1.3, 9) ## [ 0, -9, 7 ] ## -1.3 ~ -9/7 5>>> frac.med(-1.3, 9, True) ## [ -2, 5, 7 ] ## -1.3 ~ -2 + 5/7 6 7>>> frac.cont(1.3, 9) ## [ 0, 4, 3 ] ## 1.3 ~ 4/3 8>>> frac.cont(1.3, 9, True) ## [ 1, 1, 3 ] ## 1.3 ~ 1 + 1/3 9>>> frac.cont(-1.3, 9) ## [ 0, -4, 3 ] ## -1.3 ~ -4/3 10>>> frac.cont(-1.3, 9, True) ## [ -2, 2, 3 ] ## -1.3 ~ -2 + 2/3
The test TSV baselines in the test_files
directory have four columns:
denominator = 9
)denominator = 99
)denominator = 999
)make test
will run the node-based tests.
make pytest
will run the python tests against the system Python version.
make pypytest
will run the python tests against pypy
if installed
Please consult the attached LICENSE file for details. All rights not explicitly granted by the Apache 2.0 License are reserved by the Original Author.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/20 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More