Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
The frac npm package is designed to compute the fractional part of a number, effectively separating the integer part from the decimal part of a number. This can be particularly useful in mathematical, engineering, or scientific applications where precision with decimal numbers is required.
Fractional Part Extraction
This feature allows you to extract the fractional part of a number. The function returns an array where the first element is the decimal fraction, the second is the numerator, the third is the denominator, and the fourth is the sign.
const frac = require('frac');
let result = frac(4.567);
// result will be [0.567, 567, 1000, 3] representing the fraction, numerator, denominator, and sign.
Handling Negative Numbers
The package can also handle negative numbers, returning the fractional part along with the sign, which can be useful for applications that need to distinguish between positive and negative fractions.
const frac = require('frac');
let result = frac(-2.345);
// result will be [-0.345, 345, 1000, -1] indicating the fraction, numerator, denominator, and sign for negative numbers.
mathjs is a comprehensive math library for JavaScript and Node.js. It offers a wide range of functionalities including arithmetic, algebraic operations, and more. Compared to frac, mathjs is much more extensive, providing functionalities far beyond fractional part extraction.
fraction.js is focused on fraction operations, allowing for creation, manipulation, and conversion of fractions. While frac specifically extracts the fractional part of numbers, fraction.js provides a broader set of tools for working with fractions as first-class objects.
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".
With npm:
$ npm install frac
In the browser:
<script src="frac.js"></script>
The script will manipulate module.exports
if available (e.g. in a CommonJS
require
context). This is not always desirable. To prevent the behavior,
define DO_NOT_EXPORT_FRAC
From PyPI:
$ 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:
> // var frac = require('frac'); // uncomment this line if in node
> frac(1.3, 9); // [ 0, 9, 7 ] // 1.3 ~ 9/7
> frac(1.3, 9, true); // [ 1, 2, 7 ] // 1.3 ~ 1 + 2/7
> frac(-1.3, 9); // [ 0, -9, 7 ] // -1.3 ~ -9/7
> frac(-1.3, 9, true); // [ -2, 5, 7 ] // -1.3 ~ -2 + 5/7
> frac.cont(1.3, 9); // [ 0, 4, 3 ] // 1.3 ~ 4/3
> frac.cont(1.3, 9, true); // [ 1, 1, 3 ] // 1.3 ~ 1 + 1/3
> frac.cont(-1.3, 9); // [ 0, -4, 3 ] // -1.3 ~ -4/3
> 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:
>>> import frac
>>> frac.med(1.3, 9) # [ 0, 9, 7 ]
>>> frac.med(1.3, 9, True) # [ 1, 2, 7 ]
>>> frac.med(-1.3, 9) # [ 0, -9, 7 ]
>>> frac.med(-1.3, 9, True) # [ -2, 5, 7 ]
>>> frac.cont(1.3, 9) # [ 0, 4, 3 ]
>>> frac.cont(1.3, 9, True) # [ 1, 1, 3 ]
>>> frac.cont(-1.3, 9) # [ 0, -4, 3 ]
>>> frac.cont(-1.3, 9, True) # [ -2, 2, 3 ]
make test
will run the node-based tests.
Tests generated from Excel have 4 columns. To produce a similar test:
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.
FAQs
Rational approximation with bounded denominator
The npm package frac receives a total of 1,526,086 weekly downloads. As such, frac popularity was classified as popular.
We found that frac demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.