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

@sayore/dnum

v0.8.92

Published

High-precision dimensional numbers for infinite scales and micro-precision.

Readme

DNum

High-precision numbers for infinite scales.

DNum is a TypeScript library designed to handle values that exceed the limits of Number.MAX_VALUE without sacrificing micro-precision. By utilizing a dimensional hypercube model V = sd, DNum efficiently processes scales ranging from subatomic nanometers to intergalactic distances.


✨ Features

  • Infinite Scaling: Represent numbers far beyond 10308 and even 101,000,000.
  • Tracer System: Prevents precision loss (underflow) by collecting micro-amounts in separate buckets until they become significant.
  • Banking-Safe Fast-Path: Computes values up to 1015 bit-identically with standard 64-bit floats for maximum performance.
  • Scientific Functions: Native support for sqrt(), pow(n), add(), sub(), mul(), and div().
  • DNum Style Formatting: Unique visual representation using subscripts for dimensions and superscripts for precision.
  • Lossless Persistence: Full serialization including all internal tracer data.

🚀 Installation

npm install @sayore/dnum
# or
pnpm add @sayore/dnum

🧠 Core Concepts

The Dimensional Model

Instead of a massive mantissa, DNum represents values as the volume of an n-dimensional hypercube: V = sd

  • s (Side length): Normalized typically within the [1.1, 100] range.
  • d (Dimension): The scaling tier of the number.

The Tracer System

When adding 1020 and 10-5, a standard 64-bit float would simply discard the smaller number. DNum parks these "micro-informations" in a TracerSystem. Once the sum of these small amounts becomes relevant (or collapse() is called), they are fused into the main value.


🛠 Usage

Basic Arithmetic

import { DNum } from '@sayore/dnum';

const a = DNum.fromAny(1e20);
const b = DNum.fromAny(5e18);

a.add(b);
console.log(a.toScientific()); // "1.0500e+20"

Deep-Space Precision (Tracer Test)

DNum excels where hardware floats fail, such as correcting nanometers on a 300 billion km journey.

const distance = DNum.fromAny(300_000_000_000); // 300 billion meters
const correction = DNum.fromAny(0.000000001);   // 1 nanometer

for (let i = 0; i < 100000; i++) {
    distance.add(correction);
}

// collapse() merges tracers into the float, but toPreciseString()
// stitches the tracer data textually for 100% display accuracy.
console.log(distance.toPreciseString(10)); // "300000000000.0001000000"

💎 DNum Style (UI Formatting)

For games and simulations, DNum offers a compact, typographic representation:

  • Subscripts (Bottom): The Dimension (d).
  • Superscripts (Top): The Decimal precision of the side length (s).

Example Output: ₁₂12⁵⁰

const powerLevel = new DNum(12.50, 12);
console.log(powerLevel.toString(2)); 
// Output: ₁₂12⁵⁰

const powerLevel = new DNum(150.50, 12);
console.log(powerLevel.toString(2)); 
// Output: ₁₄73⁵³ (₁₂150⁵⁰ but normalized to be within 0 - 100)

📊 API Reference (Quick Look)

| Method | Description | | :--- | :--- | | add(other) | Adds another DNum (including tracer data). | | mul(other) | Multiplies and scales all internal buckets. | | sqrt() | Calculates the square root in log-space. | | pow(n) | Raises the number to the power of n. | | collapse() | Force-merges tracer content into the main value (hardware-level). | | toPreciseString(p) | Outputs exact value bypassing 64-bit rounding errors. |


⚠️ Limitations & Harsh Realities

DNum is a powerhouse for scaling, but it is not a magic bullet:

  1. The "15-Digit Window": DNum is not an Arbitrary Precision library. It uses a "moving window" of ~15 significant digits. You cannot see a grain of sand and a mountain ($10^{20}$ scale difference) perfectly at the same time in one float.
  2. Dimensional Sensitivity: At very high dimensions (d > 100), the side length $s$ becomes extremely sensitive. A tiny rounding error in $s$ can translate to a massive absolute error.
  3. Performance: It is slower than native number primitives due to the Map-based tracer management. Use it where scale matters, not for high-frequency vertex math.

💾 Persistence

// Save including all micro-tracer data
const json = playerMoney.serialize();

// Restore perfectly
const loaded = DNum.deserialize(json);

⚖️ License

MIT - Created for infinity and beyond.