int32
TypeScript icon, indicating that this package has built-in type declarations

4.0.7 • Public • Published

Int32

CI

Use Rust to compute 32-bit signed integers and wrap around at the boundary.

You need to set up the Rust development environment: rustup

Usage

add

import { add } from "int32";

const n = add(1, 2); // 3

subtract

import { subtract } from "int32";

const n = subtract(1, 2); // -1

multiply

import { multiply } from "int32";

const n = multiply(2, 6); // 12

divide

import { divide } from "int32";

const n = divide(6, 4); // 1

pow

import { pow } from "int32";

const n = pow(2, 3); // 8

shiftLeft

import { shiftLeft } from "int32";

const n = shiftLeft(5, 2); // 20

shiftRight

import { shiftRight } from "int32";

const n1 = shiftRight(5, 2); // 1
const n2 = shiftRight(6, 1); // 3
const n3 = shiftRight(-5, 1); // -3

shiftRightUnsigned

import { shiftRightUnsigned } from "int32";

const n = shiftRightUnsigned(-5, 1); // 2147483645

rotateLeft

import { rotateLeft } from "int32";

const n = rotateLeft(0b10000000000000000000000100000000, 1); // 0b00000000000000000000001000000001

rotateRight

import { rotateRight } from "int32";

const n = rotateRight(0b00000000000000000000000100000001, 8); // 0b00000001000000000000000000000001

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 4.0.7
    4
    • latest

Version History

Package Sidebar

Install

npm i int32

Weekly Downloads

5

Version

4.0.7

License

MIT

Unpacked Size

8.78 kB

Total Files

9

Last publish

Collaborators

  • magiclen