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 🙏

© 2024 – Pkg Stats / Ryan Hefner

big.esm

v1.3.1

Published

A small, fast JavaScript library for arbitrary-precision decimal arithmetic.

Downloads

14

Readme

big.esm

npm version npm downloads

Library for working with large numbers and fractions using BigInt. It provides advanced functionality for performing arithmetic operations with precision and decimal handling. Documentation.

  • 100% test coverage.
  • No dependencies.
  • No limitations on the size of the numbers, except for the limitations of BigInt, so limited by system memory =)
  • Fully written in TypeScript, so it provides type definitions out of the box.
  • Tree-shaking is supported.

Full bundle size (ESM) — 4.2 kB minified and 1.8 kB gzipped. sqrtBig operation is heavy (more than half of bundle), because it reuses most of the operations from big.esm.

Installation

Install big.esm using npm:

npm install big.esm

or yarn:

yarn add big.esm

Usage

import { createBig, addBig } from 'big.esm';

const a = createBig("12345678910.12345678910"); // or new Big("12345678910.12345678910")
const b = createBig("9876543210.9876543210");
const result = addBig(a, b);
console.log(result.toString()); // 22222222121.1111111101

Compatibility

big.esm is compatible with all modern browsers and Node.js 10+. It uses BigInt internally, so it is not compatible with older browsers and Node.js versions. On info from caniuse.com BigInt is supported by 96.47% of all browsers(as of 2023-06-25).

Notes

  • big.esm is not a drop-in replacement for big.js. It does not support the same API and does not have the same functionality. It is a completely different library.
  • sqrtBig() is heavy and slow operation. It's implemented using the Newton's method with nth root calculation. In most cases, there will be no problems.

API

More information in the documentation.

Core

new Big(value: BigValue, scale?: number | string): Big

Creates a new Big instance from a string, number or BigInt. Optionally, you can specify the scale of the number. The scale is the number of digits to the right of the decimal point. If the scale is not specified, it will be calculated automatically, otherwise the number will be rounded to integer.

Utilities

createBig(value: string | number | bigint, scale?: number | string): Big

Alias for new Big(value, scale).

cloneBig(a: Big): Big

Creates a new Big instance from another Big instance.

alignScale(a: Big, b: Big): [Big, Big]

Aligns the scale of two Big instances. The scale of the result will be equal to the maximum scale of the two numbers.

isNumericValue(value: any): boolean

Checks if the value is a valid numeric value for creating a Big instance.

Mathematical operations

In math operations mutable option is used to specify whether to mutate the first argument or create a new instance. By default, a new instance is created.

Note: In high-load applications, it is recommended to use the mutable option to reduce memory usage and improve performance.

addBig(a: Big, b: Big, mutable = false): Big

Adds two Big instances.

subBig(a: Big, b: Big, mutable = false): Big

Subtracts two Big instances.

mulBig(a: Big, b: Big, mutable = false): Big

Multiplies two Big instances.

divBig(a: Big, b: Big, precision = 20, roundingMode = "half-up", mutable = false): Big

Divides two Big instances. The default precision is 20. The default rounding mode is "half-up".

modBig(a: Big, b: Big, mutable = false): Big

Calculates the remainder of dividing two Big instances.

powBig(a: Big, exp: number, mutable = false): Big

Raises a to the power of b.

sqrtBig(a: Big, root = 2, precision = 20, mutable = false): Big

Calculates the root of a. The default root is 2, which means the square root. The default precision is 20.

absBig(a: Big, mutable = false): Big

Returns the absolute value of a.

compareBig(a: Big, b: Big): -1 | 0 | 1

Compares two Big instances. Returns -1 if a < b, 0 if a == b and 1 if a > b.

minBig(a: Big, b: Big, mutable = false): Big

Returns the minimum of two Big instances. If the numbers are equal, returns the first number.

maxBig(a: Big, b: Big, mutable = false): Big

Returns the maximum of two Big instances. If the numbers are equal, returns the first number.

Benchmark

Benchmark results are available here.

Roadmap

  • [x] Generate documentation from JSDoc
  • [x] Remove trailing zeros from toString method
  • [ ] Add formatting options
  • [ ] Add more mathematical functions

License

MIT

Copyright

© 2023 dschewchenko