
Research
/Security News
Miasma Mini Shai-Hulud Hits ImmobiliareLabs npm Packages
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.
tiny-exact-math
Advanced tools
Minimal rational arithmetic library for exact geometric predicates in pure JavaScript
Minimal rational arithmetic library for exact geometric predicates in pure JavaScript. Zero dependencies — uses native BigInt.
npm install tiny-exact-math
import { Rational, fromNumber, determinant, determinant3 } from 'tiny-exact-math';
// Create rationals
const a = new Rational(1n, 3n); // 1/3
const b = fromNumber(0.1); // exact representation of 0.1
// Arithmetic
a.add(b); // returns new Rational
a.subtract(b);
a.multiply(b);
a.divide(b);
// 2D orientation test (sign of 2×2 determinant)
// Returns +1 (counter-clockwise), -1 (clockwise), or 0 (collinear)
determinant(
{ x: 0, y: 0 },
{ x: 1, y: 0 },
{ x: 0, y: 1 }
); // +1
// 3D plane-side test (sign of 3×3 determinant)
// Returns +1 (above plane), -1 (below), or 0 (coplanar)
determinant3(
{ x: 0, y: 0, z: 0 },
{ x: 1, y: 0, z: 0 },
{ x: 0, y: 1, z: 0 },
{ x: 0, y: 0, z: 1 }
); // +1
new Rational(numerator, denominator?)Create a rational number from BigInt or number values. Automatically normalised to lowest terms with a positive denominator.
fromNumber(n)Convert a JavaScript number (integer or float) to an exact Rational. Uses the shortest decimal round-trip representation to avoid precision loss.
gcd(a, b)Greatest common divisor of two BigInt values.
| Method | Description |
|---|---|
add(other) | Addition |
subtract(other) | Subtraction |
multiply(other) | Multiplication |
divide(other) | Division |
sign() | Returns -1, 0, or 1 |
isZero() | Returns true if zero |
toNumber() | Convert to JS number (may lose precision) |
toString() | Human-readable string ("1/3") |
determinant(p1, p2, p3)Exact 2D orientation test. Returns the sign of the 2×2 determinant formed by three {x, y} points.
determinant3(p1, p2, p3, p4)Exact 3D plane-side test. Returns the sign of the 3×3 determinant formed by four {x, y, z} points.
MIT
FAQs
Minimal rational arithmetic library for exact geometric predicates in pure JavaScript
We found that tiny-exact-math demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.

Security News
Rolldown paused Rust React Compiler integration after a 5MB binary size increase raised concerns about shipping React-specific code to all Vite users.

Security News
/Research
Mini Shai-Hulud expands into the Go ecosystem after hitting LeoPlatform npm packages and targeting GitHub Actions workflows.