npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fractional-arithmetic

v1.2.3

Published

A javascript library for doing fractional arithmetic

Downloads

2,099

Readme

fractional-arithmetic.js

A javascript library for doing fractional arithmetic.

Install

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.

Example usage

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() );

API

C'tors

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

Arithmetic methods (can be chained)

.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)

Conversion methods

.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)

Helpers

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

Exceptions

If an invalid fraction is specified, a NotAFractionError is thrown. For example, Fraction('foobar') will throw an error.

Grunt targets

These targets are available

Run jshint and nodeunit tests

grunt test

Build the minified version

grunt build

Run tests and build the minified version

grunt

Feedback

Send me an email at [email protected].