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

@neutrium/math

v2.2.0

Published

Expressions, curves, numeric contracts, exact-value helpers and arithmetic backends for Neutrium applications

Readme

@neutrium/math

Mathematical expressions, curves, exact-value helpers and interchangeable numeric backends for JavaScript and TypeScript. Use native Number, BigInt, Neutrium Decimal or a configured adapter supplied by your application. Engineering units and domain rules belong to the consuming package.

API reference

Install

npm install @neutrium/math

This documentation describes the initial release being prepared. Use the install command after publication.

The package is ESM and requires Node.js 24 or newer for Node usage. It includes TypeScript declarations and supports browser bundling. Decimal is an installed dependency, but Number, BigInt, syntax and backend-independent helper imports do not load its runtime.

Choose a feature

Import the feature first, then its backend. The package root is a convenience entry for curves, not a barrel of every feature.

| Task | Start here | Guide | | --- | --- | --- | | Evaluate formulas or build a calculator | /expressions | Expressions | | Parse expression text without evaluation | /expressions/syntax | Syntax | | Evaluate, interpolate or fit curves | /curves | Curves | | Validate or store curve specifications | /curves/definitions | Persistence | | Work with exact terms and bounded values | /numeric/rational | Rational values | | Calculate exact fractions, roots and powers | /numeric/fractions, /numeric/roots, /numeric/powers | Fractions and powers | | Cancel integer products before expansion | /numeric/factors | Factors | | Write algorithms for different scalar types | /adapters/contracts and /adapters/* | Adapters | | Convert an existing scalar between adapters | /numeric/conversion | Conversion | | Implement and test a custom backend | /adapters/testing | Creating a custom adapter |

Paths in the table are relative to @neutrium/math. See the complete entry-point reference for exports and aliases.

Expressions

import { Expression } from '@neutrium/math/expressions';

Expression.evaluate('sqrt(3^2 + 4^2)'); // 5
const formula = Expression.compile('a*x + b');
formula.evaluate({ a: 2, x: 3, b: 1 }); // 7
Expression.tryEvaluate('2 +').status; // 'incomplete'
const suggestions = Expression.functions.filter(fn => fn.available);

Compile once for repeated evaluation with fresh bindings. Factories expose frozen function and constant metadata for autocomplete and help. Syntax, bindings and numeric failures have structured errors and source spans. Evaluation uses a mathematical grammar without eval or generated JavaScript.

For Decimal expressions, import Expression or createDecimalExpressionFactory from /expressions/decimal. To reuse an existing backend, use createExpressionFactory(adapter, options?) from /expressions/core.

Curves

import { Curve } from '@neutrium/math/curves';

const curve = Curve.polynomial({
    coefficients: [40, -3, -0.5],
    domain: [0, 6]
});
curve.evaluate(2);   // 32
curve.derivative(2); // -5

const fitted = Curve.fit({
    points: [[0, 40], [2, 32], [4, 20], [6, 4]],
    model: 'polynomial', degree: 2,
});
const restored = Curve.fromJSON(JSON.stringify(fitted.curve));

Curves support polynomial and power-law equations, linear and PCHIP interpolation, piecewise combinations, and regression with diagnostics. Definitions are detached, immutable data with a versioned JSON format. Decimal factories are available from /curves/decimal; adapter-based construction reuses an existing backend.

Exact values and numeric backends

import { DecimalArithmeticAdapter } from '@neutrium/math/adapters/decimal/arithmetic';
import { parseFraction } from '@neutrium/math/numeric/fractions';
import { powRational } from '@neutrium/math/numeric/powers';

const numeric = new DecimalArithmeticAdapter({ precision: 40, rounding: 'half-even' });
const third = parseFraction('1/3');
const result = powRational(numeric, numeric.from(-8), third);
numeric.toString(result); // '-2'

Use strings when input digits must survive JavaScript Number rounding. Choose the smallest adapter contract your algorithm needs: core, arithmetic or scientific. Rational extraction, construction and comparison are independent optional capabilities; their composite remains RationalArithmeticAdapter<T>.

The /numeric barrel collects backend-independent contracts and helpers. It exports no concrete adapters. Rational helpers offer validation boundaries, structured errors and a reusable RationalComputationOptions limit policy. Backend rounding and range still govern final scalar results.

License

This project is licensed under the MIT License, see the LICENSE file for details.

You are free to:

  • Use this plugin for personal or commercial purposes
  • Modify and distribute the code
  • Include it in other projects

Under the following conditions:

  • You must include the original license and copyright notice

Disclaimer

This plugin is provided "as is", without warranty of any kind. Use at your own risk.