Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@numio/bigmath

shpunter1kMIT2.4.2TypeScript support: included

@numio/bigmath is an arbitrary-precision arithmetic library. It can be used for basic operations with decimal numbers (integers and float)

precision, arithmetic, big, number, decimal, float, biginteger, bigdecimal, bignumber, bigint, bignum, infinite, longnumbers, infinitenumbers, integer, float, math, add, multiply, subtract, plus, minus, divide, long division, bigmath, numio, quartile, Q1, Q2, Q3, round, min, max, sort, mean, significant figures, MAD, Median Absolute Deviation, IQR, Interquartile Range, isEqual, equality, sqrt, square root, HEX, octal, binary, decimal, binary, cube root, FDR, Freedman-Diaconis Rule, mod

readme

@numio/bigmath: Precise Arithmetic Beyond JavaScript's Limits

@numio/bigmath is a powerful and reliable JavaScript library designed for precise numerical computations, overcoming common limitations of standard JavaScript number handling. It provides a rich set of functionalities for arithmetic, statistical analysis, data manipulation, and number base conversions, ensuring accuracy even with extremely large numbers and solving notorious floating-point precision issues like 0.1 + 0.2 !== 0.3.

Latest Update

This update introduces new functionalities:

  • Modulo Operation (mod): A new mod function has been added for performing modulo operations.
  • Pipe Function Enhancement: The mod function has been integrated into the Pipe function for seamless chaining of operations.

Existing Functionality

The application currently supports the following operations:

  • Arithmetic:
    • add: Addition of numbers.
    • sub: Subtraction of numbers.
    • mul: Multiplication of numbers.
    • div: Division of numbers.
  • Rounding:
    • round: Rounding numbers to a specified number of decimal places.
  • Data Manipulation:
    • pipe: Chaining operations together.
    • sort: Sorting arrays.
  • Statistical Measures:
    • quartile: Calculating quartiles of a dataset.
    • mean: Calculating the average of a dataset.
    • max: Finding the maximum value in a dataset.
    • min: Finding the minimum value in a dataset.
    • MAD: Calculating the Median Absolute Deviation (based on either median or mean).
    • IQR: Calculating the Interquartile Range.
    • FDR: Freedman-Diaconis rule
  • Comparison:
    • isEqual: Checking if two values are equal.
    • isLeftGreater: Checking if the left value is greater than the right value.
    • isLeftGreaterOrEqual: Checking if the left value is greater than or equal to the right value.
  • Mathematical Functions:
    • sqrt: Calculating the square root of a number.
    • cbrt: Calculating the cube root of a number.
    • abs: Calculating the absolute value of a number.
    • mod: Modulo operation, which finds the remainder when one number is divided by another
  • Number Base Conversion:
    • toBase: Converting a number to a specified base.
    • isHex: Checking if a string is a valid hexadecimal number.
    • isBinary: Checking if a string is a valid binary number.
    • isDecimal: Checking if a string is a valid decimal number.
    • isOctal: Checking if a string is a valid octal number.
    • isNumber: Checking if a value is a number.
  • Utility:
    • Benchmark: Functionality for benchmarking code execution.

Install:

NPM

npm install @numio/bigmath

YARN

yarn add @numio/bigmath

BUN

bun add @numio/bigmath

PNPM

pnpm add @numio/bigmath

DENO

deno add jsr:@numio/bigmath

#

See documentation and examples here: https://numio.deno.dev

#

Download from NPM - https://www.npmjs.com/package/@numio/bigmath

Download from JSR - https://jsr.io/@numio/bigmath

Home page - https://numio.deno.dev

Change log - https://github.com/shpunter/numio-bigmath/blob/main/CHANGELOG.md

License - https://github.com/shpunter/numio-bigmath/blob/main/LICENSE

changelog

2.4.2

Improve performance of MAD, FDR, sorting

2.4.1

Modulo - fix calculation

2.4.0

Add Mod - Modulo operation, which finds the remainder when one number is divided by another

2.3.2

FDR - change variable name to make it consistent

2.3.1

Fix import

2.2.8

Better error handling \ Add FDR - Freedman-Diaconis Rule \ MAD - median of the absolute deviations from median or mean

2.2.7

Throw an error if input is not valid. In the error show exact invalid input.

2.2.6

Optimize performance for small numbers (add operation)

2.2.5

Handle "0B", "0X", "0O", "-0B", "-0X", "-0O" as a start of the input for toBase function. \ Move documentation from README.md to web-site http://numio.deno.dev

2.2.4

Fix handling negative numbers for toBase function.

2.2.3

Add validation for negative number input in square root function \ Add validation for negative number input in cube root function

2.2.2

Throw an error if input for MAD and IQR is less than 3 elements \ Add home-page url

2.2.1

Add Number format validation examples (README.md)

2.2.0

Added isHex(str: string): boolean - Checks if a string is a valid hexadecimal number (prefixed with 0x or -0x). \ Added isBinary(str: string): boolean - Checks if a string is a valid binary number (prefixed with 0b or -0b). \ Added isDecimal(str: string): boolean - Checks if a string is a valid decimal number. \ Added isOctal(str: string): boolean - Checks if a string is a valid octal number (prefixed with 0o or -0o). \ Added isNumber(str: string): boolean - Checks if a string is a valid number in any of the formats supported by the library (decimal, hexadecimal, binary, octal).

2.1.3

Optimize performance for small numbers

2.1.2

Renamed main.ts files \ Changed import path in test files \ Change build config - run test on JSR and NPM versions

2.1.1

Fixed lib crash (NPM version)

2.1.0

Added toBase - convert number to another base \ Added abs - absolute value \ Added isLeftGreaterOrEqual - Is the left-hand side value greater \ than or equal to the right-hand side value \ Added cbrt - cube root of a number

Added Pipe().abs - absolute value in pipe \ Added Pipe().resultToBase - convert number to another base in pipe

2.0.0

The performance was improved. Adding, subtracting, dividing, and multiplying are now 2** to **5 times faster than before.\ Adding, subtracting, dividing, and multiplying support operations on HEX, octal, binary, and decimal numbers. Mixed-type calculations are allowed, with the final result converted to decimal.

1.1.0

Added sqrt - square root of a number\ Added isEqual and isLeftGreater - to compare 2 numbers.\ Added MAD - Median Absolute Deviation.\ Added IQR - Interquartile Range.