int32

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

Usage no npm install needed!

<script type="module">
  import int32 from 'https://cdn.skypack.dev/int32';
</script>

README

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

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

subtract

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

multiply

const n = int32.subtract(2, 6); // 12

divide

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

pow

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

shiftLeft

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

shiftRight

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

shiftRightUnsigned

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

rotateLeft

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

rotateRight

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

License

MIT