Published July 3, 2022 | Version 2.1.0
Software Open

nodef/extra-integer: Common operations for 32-bit integers

Creators

Description

Common operations for 32-bit integers.<br> 📦 Node.js, 🌐 Web, 📜 Files, 📰 Docs. 📘 Wiki.

A 32-bit integer can store values from −2^31 (MIN_VALUE) to 2^31 − 1 (MAX_VALUE). JavaScript converts a Number (a 64-bit floating point number) to a 32-bit integer (int32) when bitwise operators (such as |) are applied. Use is to check is a number can be represented as a 32-bit integer. Sign-based operations include signEqual and abs. Power/logarithm related operations include isPow2, prevPow2, nextPow2, pow2, pow10, log2, and log10.

This package is available in Node.js and Web formats. The web format is exposed as extra_integer standalone variable and can be loaded from jsDelivr CDN.

Stability: Experimental.

<br>

const integer = require('extra-integer');
// import * as integer from "extra-integer";
// import * as integer from "https://unpkg.com/extra-integer/index.mjs"; (deno)

integer.is(9.11e-31);
// → false

integer.log10(10000);
// → 4

integer.nextPow2(63);
// → 64

<br> <br>

Index
Property Description
MIN_VALUE Minimum int32 value.
MAX_VALUE Maximum int32 value.
is Check if value is int32.
signEqual Check if two values have equal sign.
abs Get absolute value.
isPow2 Check if value is a power-of-2.
prevPow2 Find previous power-of-2 of value.
nextPow2 Find next power-of-2 of value.
pow2 Find power-of-2 of value.
pow10 Find power-of-10 of value.
log2 Find log-base-2 of value.
log10 Find log-base-10 of value.

<br> <br>

References

<br> <br>

Files

nodef/extra-integer-2.1.0.zip

Files (27.8 kB)

Name Size Download all
md5:a121240910d0e197b0581815b4e07770
27.8 kB Preview Download

Additional details

Related works