int32
v6.0.0
Published
Use Rust to compute 32-bit signed integers and wrap around at the boundary.
Maintainers
Readme
Int32
Use Rust to compute 32-bit signed integers and wrap around at the boundary.
Requirements and Installation
Node.js 24 or later and Rust 1.88.0 or later are required. Install Rust with rustup and the native linker for your platform (a C compiler on Linux/macOS or the MSVC build tools on Windows).
npm install int32Installation compiles the native module from source using the included Cargo.lock. Package managers that block dependency build scripts must allow the int32 install script; for pnpm, approve int32 with pnpm approve-builds and rebuild it with pnpm rebuild int32. If npm requires script approval, use npm install-scripts approve int32 followed by npm rebuild int32.
Usage
add
import { add } from "int32";
const n = add(1, 2); // 3subtract
import { subtract } from "int32";
const n = subtract(1, 2); // -1multiply
import { multiply } from "int32";
const n = multiply(2, 6); // 12divide
import { divide } from "int32";
const n = divide(6, 4); // 1pow
import { pow } from "int32";
const n = pow(2, 3); // 8shiftLeft
import { shiftLeft } from "int32";
const n = shiftLeft(5, 2); // 20shiftRight
import { shiftRight } from "int32";
const n1 = shiftRight(5, 2); // 1
const n2 = shiftRight(6, 1); // 3
const n3 = shiftRight(-5, 1); // -3shiftRightUnsigned
import { shiftRightUnsigned } from "int32";
const n = shiftRightUnsigned(-5, 1); // 2147483645rotateLeft
import { rotateLeft } from "int32";
const n = rotateLeft(0b10000000000000000000000100000000, 1); // 0b00000000000000000000001000000001rotateRight
import { rotateRight } from "int32";
const n = rotateRight(0b00000000000000000000000100000001, 8); // 0b00000001000000000000000000000001