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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mark1russell7/rational

v0.1.2

Published

Exact rationals over bigint, always in lowest terms, with a correctly rounded toNumber.

Readme

@mark1russell7/rational

This package holds the exact rationals of algebra (roadmap item A2). A rational is { n, d } over bigint, always in lowest terms. The start of this package is the rationals of @mark1russell7/quantity in systems. Later, quantity imports them from here.

The value

  • The denominator d is more than 0, and gcd(n, d) is 1. Zero is 0 / 1.
  • Two equal rationals have equal fields, so equals compares the fields.
  • The functions make only values of this form. Do not make a Rational from a literal.

The functions

| Function | Result | Error | | --- | --- | --- | | rational(n, d = 1n) | The value n / d in lowest terms | Exact | | fromDecimal(text) | The value of a decimal text, for example "0.0254" or "1e-9" | Exact | | fromNumber(x) | The value of the shortest decimal that JavaScript prints for x | Exact for that decimal | | fromFloat(x) | The exact binary value of the double x. The value -0 gives 0 | Exact | | add, sub, mul, div, neg, abs, inverse | The field operations | Exact | | pow(a, e) | The power of a to an integer e | Exact | | compare, cmp, equals, sign, isInteger | The order and the tests | Exact | | floor, ceil | The nearest integer below or above | Exact | | gcd(a, b) | The greatest common divisor of two integers. It is not negative | Exact | | toString(a) | The text "n/d", or "n" for an integer | Exact | | toNumber(a) | The nearest double, with ties to even | Half a unit in the last place |

The functions div and inverse refuse a zero divisor with a RangeError. The function pow refuses 0 to a negative power.

import { add, fromDecimal, fromNumber, toNumber } from "@mark1russell7/rational";

const sum = add(fromNumber(0.1), fromNumber(0.2));
// toNumber(sum) is 0.3, because 1/10 + 2/10 is exactly 3/10.
const inch = fromDecimal("0.0254");
// inch is { n: 127n, d: 5000n }.

The two readers of a number

  • fromNumber(0.1) gives 1/10. It reads the decimal that JavaScript prints. Quantity uses it, so a decimal input of a person stays exact.
  • fromFloat(0.1) gives 3602879701896397/2^55. It reads the bits of the double. The exact evaluators use it.

The changes from quantity

  • The names of quantity stay. cmp is the same function as the new compare.
  • toNumber of quantity cuts the value to 20 digits, and then rounds it. This toNumber rounds the exact value one time, to the nearest double.
  • The new functions are fromFloat, abs, inverse, compare, equals, sign and toString.

The tests

The property tests examine the field laws on random rationals from a seed. The variable PROPERTY_RUNS sets the count of cases. The default is 1000. Other tests port the tests of quantity that use its rationals.