@jwaterfaucett/rational
v0.0.1
Published
Rational number library
Downloads
4
Readme
Rational Number Library for JavaScript
// 1/4 - 2/3
var a = Rational.create(1,4);
var b = Rational.create(2,3);
// addition
var r1 = a.add(b);
console.log(r1); // prints 11/12
// subtraction
var r2 = a.sub(b);
console.log(r2); // prints -5/12
// multiplication
var r3 = a.mul(b);
console.log(r3); // prints 1/6
// division
var r4 = a.div(b);
console.log(r4); // prints 3/8
// negation
var r5 = a.neg();
console.log(r5); // prints -1/4
// multiplicative inverse i.e. reciprocal
var r6 = b.inv();
console.log(r6); // prints 3/2