Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
JavaScript math libraries add number types and operations that the built-in Number type cannot represent exactly. A decimal library stores each value as digits with a set precision rather than as a binary floating-point number. These libraries let payment systems, accounting tools, and scientific apps calculate prices, fractions, and large integers without rounding errors.
Popularity
decimal.js has the most monthly downloads in this comparison, at 522.7M.
function toDER(enc) {
var r = this.r.toArray();
var s = this.s.toArray();
// Pad values if (r[0] & 0x80)
r = [ 0 ].concat(r);
// Pad values if (s[0] & 0x80)
s = [ 0 ].concat(s);
r = rmPadding(r);
s = rmPadding(s);
while (!s[0] && !(s[1] & 0x80)) {
s = s.slice(1);
}
var arr = [ 0x02 ];
constructLength(arr, r.length);
arr = arr.concat(r);
arr.push(0x02);
constructLength(arr, s.length);
var backHalf = arr.concat(s);
var res = [ 0x30 ];
constructLength(res, backHalf.length);
res = res.concat(backHalf);
return utils.encode(res, enc);
}
export function formatAmountAsFraction(n: number | null | string): string {
if (n == null || n === "") return "";
const num = typeof n === "string" ? parseFloat(n) : n;
if (isNaN(num)) return String(n);
if (Number.isInteger(num)) return String(num);
try {
// Use fraction.js with simplification to handle floating point imprecision // Tolerance of 0.01 allows 0.333 to become 1/3, 0.666 to become 2/3, etc. const frac = new Fraction(num).simplify(0.01);
const wholePart = Math.floor(Math.abs(num));
const isNegative = num < 0;
// Get the fractional part const fracPart = frac.mod(1).abs();
if (fracPart.valueOf() === 0) {
// It's a whole number after simplification return String(Math.round(num));
}
const fractionStr = fracPart.toFraction();
const unicodeFrac = toUnicodeFraction(fractionStr);
// Check if we got a reasonable fraction (denominator <= 16) // If not, fall back to decimal const denominator = fracPart.d;
if (denominator > 16) {
return formatAmountAsDecimal(num);
}
const sign = isNegative ? "-" : "";
if (wholePart === 0) {
return `${sign}${unicodeFrac}`;
}
return `${sign}${wholePart} ${unicodeFrac}`;
} catch {
// If fraction.js fails, fall back to decimal return formatAmountAsDecimal(num);
}
}
decimal.js-light
Provides an arbitrary-precision Decimal type for JavaScript.
function rangeStep(start: Decimal, end: Decimal, step: Decimal): Array<number> {
let num = new Decimal(start);
let i = 0;
const result: Array<number> = [];
// magic number to prevent infinite loop while (num.lt(end) && i < 100000) {
result.push(num.toNumber());
const next = num.add(step);
/*
* A non-positive step, or one too small to change `num` at Decimal's
* current precision, leaves `num.lt(end)` true forever. Stop instead of
* emitting 100000 identical values up to the iteration cap. This happens
* with subnormal domains (the computed step collapses to zero) and with
* very large values where adding a small step rounds back to the same
* Decimal.
*/
if (!next.gt(num)) {
break;
}
num = next;
i++;
}
return result;
}
big.js
Provides arbitrary-precision decimal arithmetic through a small numeric API.
median(options?: { axis?: 0 | 1 }): Series {
const { axis } = { axis: 1, ...options }
if (this.$frameIsNotCompactibleForArithmeticOperation()) {
throw Error("TypeError: median operation is not supported for string dtypes");
}
if ([0, 1].indexOf(axis) === -1) {
throw Error("ParamError: Axis must be 0 or 1");
}
const newData = this.$getDataByAxisWithMissingValuesRemoved(axis)
const resultArr = newData.map(arr => median(arr))
if (axis === 0) {
return new Series(resultArr, { index: this.columns });
} else {
return new Series(resultArr, { index: this.index });
}
}
FAQ
decimal.js suits decimal arithmetic with a configurable precision. Fraction.js suits exact rational values. Math.js suits apps that evaluate math expressions with units, matrices, and complex numbers.
A decimal library such as decimal.js or big.js stores values as decimal digits. Calculations then round only at the precision the code sets.
Math.js is a math library for JavaScript and Node.js with an expression parser. It supports units, matrices, complex values, and several numeric types.
JavaScript has a built-in BigInt type for integers of any size. BN.js and long.js offer integer classes with their own APIs, including bitwise operations.
decimal.js offers a larger API with significant-digit rounding. big.js keeps a smaller decimal API with precision controls focused on division.
For coding agents
Found your math library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.