Nocturnal Pumpkin Maelstrom
Miss any of our Open RFC calls?Watch the recordings here! »

int32

3.0.2 • Public • Published

Int32

Introduction

This module uses Rust to compute 32-bit signed integers and wrap around at the boundary.

In JavaScript, the size of type number is 64 bits. A number can be used to represent an IEEE-754 double-precision number or a 53-bit integer. If you need to compute something and integers in your computation are overflowing/underflowing, this kind of algorithms is hard to be implemented by using the type number in Node.js.

Installation

Setting up your Rust development environment: rustup

Run npm i or npm install to install.

npm install int32

If you want to save this module to package.json, add the --save option.

npm install int32 --save

Initialization

const int32 = require('int32');
import int32 from 'int32';

Usage

add

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

subtract

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

multiply

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

divide

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

pow

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

shiftLeft

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

shiftRight

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

shiftRightUnsigned

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

rotateLeft

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

rotateRight

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

License

MIT

Install

npm i int32

DownloadsWeekly Downloads

26

Version

3.0.2

License

MIT

Unpacked Size

14.7 kB

Total Files

11

Last publish

Collaborators

  • avatar