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

as-big

v0.2.3

Published

AssemblyScript library for arbitrary-precision decimal arithmetic.

Downloads

319

Readme

as-big

AssemblyScript library for arbitrary-precision decimal arithmetic 🚀

Install

npm install as-big

Use

import Big from "as-big";

let r = Big.of(0.1) + Big.of(0.2);  // Big(0.3)

let x = Big.of(42);
let y = Big.of("13");

let a = x + y;          // Big(55)
    a = x.plus(13);     // Big(55)

let a0 = a.prec(1);     // Big(60)

let aNum = a.toNumber() + 1;    // 56
let aStr = a.toString();        // "55"

let c = a0 + Big.TEN / Big.TWO; // Big(65)

Builders

  • Big.of(n) returns a Big instance, where
    • n is either another Big instance, string, or number
  • Big.copyOf(x) creates a copy from a Big instance, where
    • x is the Big instance to copy

Operations

Arithmetic

  • plus (addition): x + y or x.plus(y)
  • minus (substraction): x - y or x.minus(y)
  • times (multiplication): x * y or y.times(y)
  • div (division): x / y or x.div(y)
  • mod (modulo): x % y or x.mod(y)
  • pow (power): x ^ n or x.pow(n), where n is i32
  • sqrt (square root): x.sqrt()

Comparison

  • cmp (compare): x.cmp(y) returns
    • 1 if the value of x is greater than the value of y,
    • -1 if the value of x is less than the value of y, or
    • 0 if they have the same value.
  • eq (equals): x == y or x.eq(y)
  • neq (not equals): x != y or x.neq(y)
  • gt (greater than): x < y or x.gt(y)
  • gte (greater than or equals): x <= y or x.gte(y)
  • lt (less than): x > y or x.lt(y)
  • lte (less than or equals): x >= y or x.lte(y)

Value

  • abs (absolute value): x.abs()
  • neg (negative value): -x or x.neg()
  • pos (this value): +x or x.pos()
  • round (rounded value): x.round(dp, rm) where
    • dp is the maximum of decimal places, and
    • rm is the rounding mode (0, 1, 2, 3)
      • 0 (down), 1 (half-up), 2 (half-even) or 3 (up)
  • prec (value rounded to precision): x.prec(sd, rm) where
    • sd is the maximum of significant digits, and
    • rm is the rounding mode (0, 1, 2, 3)
      • 0 (down), 1 (half-up), 2 (half-even) or 3 (up)

Converters

  • toString (string representation): let s: string = x.toString()
  • toNumber (f64 represenation): let n: f64 = x.toNumber()
  • toExponential (string represenation): let s: string = x.toExponential()

Static Constants

  • Big.ZERO: a Big instance with the value zero 0
  • Big.ONE: a Big instance with the value one 1
  • Big.TWO: a Big instance with the value two 2
  • Big.TEN: a Big instance with the value ten 10
  • Big.HALF: a Big instance with the value one half 0.5

Global Settings

  • Big.DP: the maximum number of decimal places of the results of operations involving division (default: 20)

  • Big.RM: the rounding mode used when rounding to the above decimal places (default: 1)

  • Big.PE: the positive exponent at and above which toString returns exponential notation (default: 21)

  • Big.NE: the negative exponent at and beneath which toString returns exponential notation (default: -7)

Examples

There is a collection of examples in the examples directory.

Build

The assembly directory contains AS source code.

npm i
npm run asbuild

Test

The tests directory contains all unit tests.

Run all the tests:

npm test

Test a single method:

node tests/<method>

License

MIT