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

monsterfloat

v1.0.7

Published

Arbitrary-length rational numbers

Downloads

8

Readme

MonsterFloat - Arbitrary Precision Rational Numbers

A TypeScript library for exact arithmetic operations using rational numbers. Unlike floating-point numbers, MonsterFloat represents numbers as fractions with arbitrary-precision integers (using BigInt), ensuring exact calculations without rounding errors.

Features

  • Exact arithmetic operations (no floating-point errors)
  • Automatic fraction simplification
  • Support for arbitrary-precision numbers
  • Seamless conversion between number types

Installation

npm install monsterfloat

Usage

Basic Operations

import { MonsterFloat } from 'monsterfloat';

// Create fractions
const half = new MonsterFloat(1n, 2n);        // 1/2
const third = new MonsterFloat(1n, 3n);       // 1/3

// Perform calculations
const sum = half.add(third);                  // 5/6
const product = half.multiply(third);         // 1/6
const quotient = half.divide(third);          // 3/2
const power = half.pow(3);                    // 1/8

// Short-form aliases
const result = half.a(third).m(2).d(4);      // (1/2 + 1/3) * 2 / 4

Comparison Operations

const a = new MonsterFloat(1n, 2n);
const b = new MonsterFloat(3n, 4n);

a.isEqual(0.5);                // true
a.isLessThan(b);              // true
a.isGreaterThanOrEqual(0.25); // true

Conversion Methods

const num = new MonsterFloat(355n, 113n);

num.toNumber();           // 3.1415929203539825 (as JavaScript number)
num.toString();           // "355/113"
num.toNumberString(5n);   // "3.14159" (with specified precision)

Creating from Different Types

MonsterFloat.from(0.5);         // From number
MonsterFloat.from("1.23");      // From string
MonsterFloat.from(42n);         // From BigInt

API Reference

Constructor

  • new MonsterFloat(numerator: bigint, denominator: bigint)

Instance Methods

Arithmetic

  • add(other: Numeric) or a(other) - Addition
  • subtract(other: Numeric) or s(other) - Subtraction
  • multiply(other: Numeric) or m(other) - Multiplication
  • divide(other: Numeric) or d(other) - Division
  • pow(other: Numeric) or p(other) - Exponentiation

Comparison

  • isEqual(other: Numeric)
  • isLessThan(other: Numeric)
  • isLessThanOrEqual(other: Numeric)
  • isGreaterThan(other: Numeric)
  • isGreaterThanOrEqual(other: Numeric)

Conversion

  • toNumber(): number
  • toString(): string
  • toFractionString(): string
  • toNumberString(precision: bigint): string

Static Methods

  • from(value: Numeric | string): MonsterFloat

Examples

Exact Decimal Arithmetic

const price = MonsterFloat.from("10.99");
const quantity = MonsterFloat.from(3);
const total = price.multiply(quantity);      // Exactly 32.97

Complex Calculations

const result = MonsterFloat.from(1)
  .divide(7)                                // 1/7
  .multiply(7)                             // 1
  .isEqual(1);                            // true (no floating point errors!)