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

big-rat

v1.0.4

Published

A big integer rational number

Downloads

320,211

Readme

big-rat

Arbitrary precision rational number arithmetic

build status

Example

Program

var rat = require('big-rat')

//Construct a pair of rational numbers;
//   a = 1/10
//   b = 2/10
var a = rat(1, 10)
var b = rat(2, 10)

//Compute their sum
var add = require('big-rat/add')
var c = add(a, b)

//Print out sum
var toString = require('big-rat/to-string')
console.log('a+b=', toString(c))

//And also convert to a number
var toFloat = require('big-rat/to-float')
console.log('exact rational result:', toFloat(c))

//For comparison, here is the same computation performed with floats
var x = 0.1
var y = 0.2
console.log('approximate float result:', x + y)

Output

a+b= 3/10
exact rational result: 0.3
approximate float result: 0.30000000000000004

Install

npm i big-rat

API

var r = require('big-rat')(n[, d])

Constructs a rational number as the quotient n/d

  • n is the numerator. Can be a float, string, bignum or rational
  • d is the denominator (optional, default 1)

Returns A rational number

var f = require('big-rat/to-float')(r)

Returns The closest floating point number to r

var s = require('big-rat/to-string')(r)

Returns A string representing the big rat r

var b = require('big-rat/is-rat')(r)

Returns true if r is a big rat

var c = require('big-rat/add')(a, b)

Returns a+b

var c = require('big-rat/sub')(a, b)

Returns a-b

var c = require('big-rat/mul')(a, b)

Returns a*b

var c = require('big-rat/div')(a, b)

Returns a/b

var c = require('big-rat/neg')(a)

Returns -a

var c = require('big-rat/recip')(a)

Returns 1/a

var c = require('big-rat/sign')(a)

Returns One of the following values:

  • -1 if a<0
  • 0 if a=0
  • +1 if a>0

var c = require('big-rat/abs')(a)

Returns |a|

var c = require('big-rat/min')(a, b)

Returns min(a,b)

var c = require('big-rat/max')(a, b)

Returns max(a,b)

var c = require('big-rat/equals')(a, b)

Returns true if a=b, false otherwise

var c = require('big-rat/cmp')(a, b)

Returns

  • -1 if a<b
  • 0 if a=b
  • +1 if a>b

License

(c) 2015 MIT License