https://github.com/nodef/extra-integer
A 32-bit integer can store values from -2^31 to 2^31 - 1.
https://github.com/nodef/extra-integer
32bit abs bit extra integer is is-pow-2 log-10 log-2 next-pow-2 pow-10 pow-2 prev-pow-2 sign-equal
Last synced: 9 months ago
JSON representation
A 32-bit integer can store values from -2^31 to 2^31 - 1.
- Host: GitHub
- URL: https://github.com/nodef/extra-integer
- Owner: nodef
- License: mit
- Created: 2018-05-12T17:18:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-04-08T16:40:49.000Z (9 months ago)
- Last Synced: 2025-04-19T07:52:13.896Z (9 months ago)
- Topics: 32bit, abs, bit, extra, integer, is, is-pow-2, log-10, log-2, next-pow-2, pow-10, pow-2, prev-pow-2, sign-equal
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/extra-integer
- Size: 342 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Citation: CITATION.cff
Awesome Lists containing this project
README
A [32-bit integer] can store values from `-2^31` to `2^31 - 1`.
📦 [Node.js](https://www.npmjs.com/package/extra-integer),
🌐 [Web](https://www.npmjs.com/package/extra-integer.web),
📜 [Files](https://unpkg.com/extra-integer/),
📰 [Docs](https://nodef.github.io/extra-integer/),
📘 [Wiki](https://github.com/nodef/extra-integer/wiki/).
This package deals with the manipulation of **32-bit integers** in JavaScript,
which can store values ranging 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 [abs] and [signEqual]. **Power/logarithm**
related operations include [isPow2], [prevPow2], [nextPow2], [pow2], [pow10],
[log2], and [log10].
This package is available in *Node.js* and *Web* formats. To use it on the web,
simply use the `extra_integer` global variable after loading with a ``
tag from the [jsDelivr CDN].
> Stability: [Experimental](https://www.youtube.com/watch?v=L1j93RnIxEo).
[32-bit integer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
[jsDelivr CDN]: https://cdn.jsdelivr.net/npm/extra-integer.web/index.js
<br>
```javascript
const xinteger = require('extra-integer');
// import * as xinteger from "extra-integer";
// import * as xinteger from "https://unpkg.com/extra-integer/index.mjs"; (deno)
xinteger.is(9.11e-31);
// → false
xinteger.log10(10000);
// → 4
xinteger.nextPow2(63);
// → 64
```
<br>
<br>
## Index
| Property | Description |
| ---- | ---- |
| [MIN_VALUE] | Minimum int32 value. |
| [MAX_VALUE] | Maximum int32 value. |
| | |
| [is] | Check if value is int32. |
| | |
| [abs] | Get the absolute of an int32. |
| [signEqual] | Check if two int32s have equal sign. |
| | |
| [isPow2] | Check if int32 is a power-of-2. |
| [prevPow2] | Find previous power-of-2 of an int32. |
| [nextPow2] | Find next power-of-2 of an int32. |
| [pow2] | Find the power-of-2 of an int32. |
| [pow10] | Find the power-of-10 of an int32. |
| [log2] | Find the base-2 logarithm of an int32. |
| [log10] | Find the base-10 logarithm of an int32. |
<br>
<br>
## References
- [Bit Twiddling Hacks by Sean Eron Anderson](https://graphics.stanford.edu/~seander/bithacks.html)
- [bit-twiddle package by @mikolalysenko](https://www.npmjs.com/package/bit-twiddle)
<br>
<br>
[](https://www.youtube.com/watch?v=EK32jo7i5LQ)<br>
[](https://nodef.github.io)
[](https://zenodo.org/badge/latestdoi/133167597)
[](https://coveralls.io/github/nodef/extra-integer?branch=master)
[](https://codeclimate.com/github/nodef/extra-integer/test_coverage)
[](https://codeclimate.com/github/nodef/extra-integer/maintainability)

[MIN_VALUE]: https://github.com/nodef/extra-integer/wiki/MIN_VALUE
[MAX_VALUE]: https://github.com/nodef/extra-integer/wiki/MAX_VALUE
[is]: https://github.com/nodef/extra-integer/wiki/is
[signEqual]: https://github.com/nodef/extra-integer/wiki/signEqual
[abs]: https://github.com/nodef/extra-integer/wiki/abs
[isPow2]: https://github.com/nodef/extra-integer/wiki/isPow2
[prevPow2]: https://github.com/nodef/extra-integer/wiki/prevPow2
[nextPow2]: https://github.com/nodef/extra-integer/wiki/nextPow2
[pow2]: https://github.com/nodef/extra-integer/wiki/pow2
[pow10]: https://github.com/nodef/extra-integer/wiki/pow10
[log2]: https://github.com/nodef/extra-integer/wiki/log2
[log10]: https://github.com/nodef/extra-integer/wiki/log10