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

base-math

v1.0.2

Published

Used to perform basic math operations against different base numbering systems.

Downloads

5

Readme

base-math

base-math is a package that performs basic mathematical operations regardless of number base. When provided a respective base (binary, octal, hex) base-math will convert the provided numbers to integers, perform the operation, and return the result in requested base.

Installion

npm install base-math --save

API

var bmath = require('base-math')();

usage

base-math takes two required parameters and one optional base parameter. For example, bmath.add('101', '1221', 8) would return 1322 in base 8. The package defaults to a base 10 numbering system so that the same operation bmath.add('101', '1221') without a base type would also result in 1322 with an entirely different meaning. Basically, be aware of what you're converting.

At this time, base-math does not support mixed number types. Both numbers should be of the same base.

methods

add(x, y, base)

Adds two numbers and returns the result. Takes an optional base parameter. Defaults to base 10.

var hexNum = bmath.add('3e2a', '1e1d', 16);
var octNum = bmath.add('363', '031', 8);
var binary = bmath.add('11001101', '10101110', 2);
var float  = bmath.add(4.3, 3.2);
var number = bmath.add(45, 21);
subtract(x, y, base)

Subtracts two numbers and returns the result. Takes an optional base parameter. Defaults to base 10.

var hexNum = bmath.subtract('3e2a', '1e1d', 16);
var octNum = bmath.subtract('363', '031', 8);
var binary = bmath.subtract('11001101', '10101110', 2);
var float  = bmath.subtract(4.3, 3.2);
var number = bmath.subtract(45, 21);
divide(x, y, base)

Divides two numbers and returns the result. Takes an optional base parameter. Defaults to base 10.

var hexNum = bmath.divide('3e2a', '1e1d', 16);
var octNum = bmath.divide('363', '031', 8);
var binary = bmath.divide('11001101', '10101110', 2);
var float  = bmath.divide(4.3, 3.2);
var number = bmath.divide(45, 21);
multiply(x, y, base)

Multiplies two numbers and returns the result. Takes an optional base parameter. Defaults to base 10.

var hexNum = bmath.multiply('3e2a', '1e1d', 16);
var octNum = bmath.multiply('363', '031', 8);
var binary = bmath.multiply('11001101', '10101110', 2);
var float  = bmath.multiply(4.3, 3.2);
var number = bmath.multiply(45, 21);
sqrt(x, y, base)

Returns the square root of a number. If an integer, returns the value as a float. Takes an optional number base parameter. Defaults to base 10.

var hexNum = bmath.sqrt('3e2a', 16);
var octNum = bmath.sqrt('363',8);
var binary = bmath.sqrt('11001101', 2);
var float  = bmath.sqrt(4.3);
var number = bmath.sqrt(45);
pow(x, y, base)

Returns the power of two numbers. X is base number and Y is the exponent. The exponent is a real number in base 10 (for example, 2 or 2.13). Takes an optional number base parameter. Defaults to base 10.

var hexNum = bmath.pow('3e2a', 3, 16);
var octNum = bmath.pow('363', 2, 8);
var binary = bmath.pow('11001101', 3, 2);
var float  = bmath.pow(4.3, 2);
var number = bmath.pow(2, 8);

Infinity, MAX_SAFE_INTEGER, and MIN_SAFE_INTEGER

MAX_SAFE_INTEGER

base-math performs a check to see if either of the parameters or the product of the parameters exceeds the MAX_SAFE_INTEGER. If so, a message is written to the console.log.

MIN_SAFE_INTEGER

base-math performs a check to see if either of the parameters or the product of the parameters is less than the MIN_SAFE_INTEGER. If so, a message is written to the console.log.

Infinity

If either of the parameters or the product of the parameters exceeds the MAX_VALUE base-math returns 'Infinity'

License

MIT