
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
fractional-arithmetic
Advanced tools
A javascript library for doing fractional arithmetic.
First do an npm install fractional-arithmetic.
Then, load the library into your code: var Fraction = require('fractional-arithmetic').Fraction;.
You're good to go.
var f = new Fraction( 7, 24 );
var g = Fraction( 11, 30 );
console.log( 'f=', f, 'g=', g );
console.log( 'f + g = ', f.plus(g) );
console.log( 'f - g = ', f.minus(g) );
console.log( 'f x g = ', f.times(g) );
console.log( 'f / g = ', f.dividedBy(g) );
console.log( 'latex f:', f.toLatex() );
console.log( 'number f:', f.toNumber() );
var pi= Fraction( 3.1415926 );
console.log( 'from decimal pi:', pi, pi.simplify() );
Fraction(n,d) creates the fraction "n over d" (n and d must be integers)
Fraction(f) if f is fraction, creates a new fraction equal to fraction f
Fraction(d) if f is decimal number, creates a new fraction equal to decimal number d
.add(f), .plus(f) both add fraction f to this fraction
.add(n,d), .plus(n,d) both add "n over d" to this fraction (n and d must be integers)
.minus(f) subtracts fraction f from this fraction
.minus(n,d) subtracts "n over d" from this fraction (n and d must be integers)
.times(f), .multiply(f) both multiply this fraction with fraction f
.times(n,d), .multiply(n,d) both multiply this fraction with fraction "n over d" (n and d must be integers)
.dividedBy(f), .div(f) both divide this fraction with fraction f
.dividedBy(n,d), .div(n,d) both divide this fraction with fraction "n over d" (n and d must be integers)
.inverse() returns the inverse of this fraction (flips numerator & denominator)
.toString(), toS(), inspect() return a human-readable string of this fraction
.toLatex() returns the fraction as a LaTeX command string
.toMathML() returns the fraction as a MathML string
.toNumber() returns the fraction as a decimal number (divides numerator by denominator)
If you need to use these you can import them separately, like so:
var gcd = require('fractional-arithmetic').gcd;
gcd(a,b) computes the Greatest Common Divisor of a and b
lcm(a,b) computes the Least Common Multiple of a and b
isInteger(n) true iff n is an integer
If an invalid fraction is specified, a NotAFractionError is thrown. For example, Fraction('foobar') will throw an error.
These targets are available
grunt test
grunt build
grunt
Send me an email at alex.georgiou@gmail.com.
FAQs
A javascript library for doing fractional arithmetic
The npm package fractional-arithmetic receives a total of 472 weekly downloads. As such, fractional-arithmetic popularity was classified as not popular.
We found that fractional-arithmetic 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.