https://github.com/magiclen/node-int32
Use Rust to compute 32-bit signed integers and wrap around at the boundary.
https://github.com/magiclen/node-int32
int32 nodejs rust
Last synced: about 2 months ago
JSON representation
Use Rust to compute 32-bit signed integers and wrap around at the boundary.
- Host: GitHub
- URL: https://github.com/magiclen/node-int32
- Owner: magiclen
- License: mit
- Created: 2017-06-20T15:29:10.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-11-26T17:22:13.000Z (6 months ago)
- Last Synced: 2025-03-24T17:55:19.461Z (2 months ago)
- Topics: int32, nodejs, rust
- Language: JavaScript
- Homepage:
- Size: 1.7 MB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Int32
=================================[](https://github.com/magiclen/node-int32/actions/workflows/ci.yml)
Use Rust to compute 32-bit signed integers and wrap around at the boundary.
You need to set up the Rust development environment: [rustup](https://rustup.rs/)
## Usage
#### add
```typescript
import { add } from "int32";const n = add(1, 2); // 3
```#### subtract
```typescript
import { subtract } from "int32";const n = subtract(1, 2); // -1
```#### multiply
```typescript
import { multiply } from "int32";const n = multiply(2, 6); // 12
```#### divide
```typescript
import { divide } from "int32";const n = divide(6, 4); // 1
```#### pow
```typescript
import { pow } from "int32";const n = pow(2, 3); // 8
```#### shiftLeft
```typescript
import { shiftLeft } from "int32";const n = shiftLeft(5, 2); // 20
```#### shiftRight
```typescript
import { shiftRight } from "int32";const n1 = shiftRight(5, 2); // 1
const n2 = shiftRight(6, 1); // 3
const n3 = shiftRight(-5, 1); // -3
```#### shiftRightUnsigned
```typescript
import { shiftRightUnsigned } from "int32";const n = shiftRightUnsigned(-5, 1); // 2147483645
```#### rotateLeft
```typescript
import { rotateLeft } from "int32";const n = rotateLeft(0b10000000000000000000000100000000, 1); // 0b00000000000000000000001000000001
```#### rotateRight
```typescript
import { rotateRight } from "int32";const n = rotateRight(0b00000000000000000000000100000001, 8); // 0b00000001000000000000000000000001
```## License
[MIT](LICENSE)