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

bdi

v0.0.1

Published

A dumb arbitrary precision maths library built to help me with Project Euler problems and node development. DON'T USE IT, there are much better altenatives.

Downloads

2

Readme

Big-Dumb-Integer

Don't use this for anything, really.

Big Dumb Integer (or BDI) is a JavaScript library built as an exercise to allow arbitrary precision integer maths in the language.

BDI was developed as a learning project to aid with solving Project Euler problems in JavaScript.

There are other libraries out there that provide arbitrary precision mathematics solutions for users of JavaScript that are smaller, and much, much better. The author recommends Peter Olson's BigInteger.js and Silent Matt's biginteger alternatives. They were both highly-used sources of inspiration in the building of this project.

What it does

BDI stores integers in a 'Big' object and supports comparison, addition, subtraction and multiplication of positive and negative integers in base 10. That's right, as yet, there is no support for division. That's because division tends to lend itself to floating point maths and that stuff is hard. Maybe one day, when the next Project Euler problem requires it.

Requiring the library

var Big = require('Big-Dumb-Integer').Big;

The 'Big' Object

Each 'Big' object is instantiated by calling new Big(number) where number can be:

  • a number
  • a string
  • an array of single digit numbers (negative numbers can be passed if the first value is a string equal to '-'). Only limited checking of this applies.
  • another Big object

Object Properties

.sign

Either 'POSITIVE', 'NEGATIVE' or 'NEUTRAL'

.number

An array of single digit integer values

Object Methods

Object methods return new Big object instances, in this way the both leave the original object as is and allow for method chaining.

var Big = require('Big-Dumb-Integer').Big;
var a = new Big('-10');
var b = new Big(12);

var c = a.add(b);

console.log(a.toString()); // '-10'
console.log(b.toString()); // '12'
console.log(c.toString()); // '2'

.abs()

Takes any accepted input and returns a new Big object with the sign 'POSITIVE'. This means it is currently broken for Zero but that bug is required by .subtract().

.add(input)

Takes any accepted input adds it to the current Big object and returns a new Big object.

.eq(input)

Takes any accepted input and returns true if equal to current object or false otherwise.

.gt(input)

Takes any accepted input and returns true if the current object is the greater of the two.

.gte(input)

Takes any accepted input and returns true if the current object is greater than or equal to the input value.

.invert()

Invert Big..sign (multiplies by -1).

.listify()

Converts a Big object to an array. Not especially useful.

.lt(input)

Takes any accepted input and returns true if the current object is the lesser of the two.

.lte(input)

Takes any accepted input and returns true if the current object is less than or equal to the input value.

.minus(input)

Alias for .subtract()

.multiply(input)

Takes any accepted input, multiplies it by the current object and returns a new Big object.

.numify()

Converts a Big object to a number. Likely to be buggy, not yet tested with large integers.

.toString()

Converts a Big object to a String.

.plus(input)

Alias for .add().

.subtract(input)

Takes any accepted input, subtracts it from the current object and returns a new Big object.

.take(input)

Alias for .subtract()

.trimLeadingZeroes()

A helper method that removes any leading zeroes from Big.number. Used in .subtract() and .multiply() methods.