npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

int64-napi

v4.0.1

Published

Use Rust to compute 64-bit signed integers.

Downloads

10,733

Readme

Int64

CI

Use Rust to compute 64-bit signed integers.

You need to set up the Rust development environment: rustup

Usage

First of all, an int64(long) value can be represented by

  1. An Int64 object (instance).
  2. A 53-bit integer number.
  3. A string of a decimal number.
  4. A string of a hexadecimal number, starting with 0x.
  5. A string of an octal number, starting with 0o.
  6. A string of a binary number, starting with 0b.
  7. A buffer with 8 bytes

Static

Static funtions are used for quickly getting the final result as a JavaScript number. If you have several 64-bit integer computations to be done, it is better to use class methods instead.

A JavaScript number can safely represent only from -(2^53 - 1) to 2^53 - 1, and this library does not allow you to convert an unsafe-ranged integer to a JavaScript number.

Random

import { random } from "int64-napi";

const n = random(9876543210, "12345678901234"); // 5724595911391

Add

import { add } from "int64-napi";

const n = add("0x0000000000000001", 0x00000002); // 1 + 2 = 3

Subtract

import { subtract } from "int64-napi";

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

multiply

import { multiply } from "int64-napi";

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

divide

import { divide } from "int64-napi";

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

mod

import { mod } from "int64-napi";

const n = mod(6, 4); // 6 % 4 = 2

shiftLeft

import { shiftLeft } from "int64-napi";

const n = shiftLeft(0b00101, 2); // 0b000101 << 2 = 0b010100

shiftRight

import { shiftRight } from "int64-napi";

const n1 = shiftRight(0b0101, 2); // 0b0101 >> 2 = 0b0001
const n2 = shiftRight(0b0110, 1); // 0b0110 >> 1 = 0b0011
const n3 = shiftRight("0b1111111111111111111111111111111111111111111111111111111111111011", 1); // 0b1111111111111111111111111111111111111111111111111111111111111011 >> 1 = 0b1111111111111111111111111111111111111111111111111111111111111101

shiftRightUnsigned

import { shiftRightUnsigned } from "int64-napi";

const n = shiftRightUnsigned("0b1111111111111111111111111111111111111111111111111111111111111011", 32); // 0b1111111111111111111111111111111111111111111111111111111111111011 >>> 32 = 0b0000000000000000000000000000000011111111111111111111111111111111

rotateRight

import { rotateRight } from "int64-napi";

const n = rotateRight("0x0000000080000100", 20); // 0x0010000000000800

rotateLeft

import { rotateLeft } from "int64-napi";

const n = rotateLeft("0x0010000000000800", 20); // 0x0000000080000100

and

import { and } from "int64-napi";

const n = and("0x000000000000FFFF", "0x0123456789ABCDEF"); // 0x000000000000CDEF

or

import { or } from "int64-napi";

const n = or("0x0000FFFF0000FFFF", "0xFFFFFFFFFFFF0000"); // 0xFFFFFFFFFFFFFFFF

xor

import { xor } from "int64-napi";

const n = xor("0x0000FFFF0000FFFF", "0xFFFFFFFFFFFF0000"); // 0xFFFF0000FFFFFFFF

nand

import { nand } from "int64-napi";

const n = nand("0x000000000000FFFF", "0x0123456789ABCDEF"); // 0xFFFFFFFFFFFF3210

nor

import { nor } from "int64-napi";

const n = nor("0x0000FFFF0000FFFF", "0xFFFFFFFFFFFF0000"); // 0x0000000000000000

xnor

import { xnor } from "int64-napi";

const n = xnor("0x0000FFFF0000FFFF", "0xFFFFFFFFFFFF0000"); // 0x0000FFFF00000000

not

import { nor } from "int64-napi";

const n = nor("0x0000FFFF0000FFFF", "0xFFFFFFFFFFFF0000"); // 0x0000000000000000

eq (Equal)

import { eq } from "int64-napi";

const n = eq("0x0000FFFF0000FFFF", "281470681808895"); // true

ne (Not Equal)

import { ne } from "int64-napi";

const n = ne("0x0000FFFF0000FFFF", "0x0000FFFF00000000"); // true

gt (Greater Than)

import { gt } from "int64-napi";

const n = gt("0x0000FFFF0000FFFF", "0x0000FFFF00000000"); // true

gte (Greater Than or Equal)

import { gte } from "int64-napi";

const n = gte("0x0000FFFF0000FFFF", "0x0000FFFF00000000"); // true

lt (Less Than)

import { lt } from "int64-napi";

const n = lt("0x0000FFFF0000FFFF", "0x0000FFFF0000FFFF"); // false

lte (Less Than or Equal)

import { lte } from "int64-napi";

const n = lte("0x0000FFFF0000FFFF", "0x0000FFFF0000FFFF"); // true

comp (Compare)

If a < b, returns -1.

If a === b, returns 0.

If a > b, returns 1.

import { comp } from "int64-napi";

const a = comp("0x0000FFFF0000FFFF", "0x0000FFFF0000FFFF"); // 0
const b = comp("0x0000FFFF0000FFFF", "0x0000FFFF00000000"); // 1
const c = comp("0x0000FFFF00000000", "0x0000FFFF0000FFFF"); // -1

Instance / Object

Create an Instance

import { Int64 } from "int64-napi";

const i64 = new Int64(1);

Methods

Int64 instance has methods which are corresponding to static functions. Int64 instances are mutable and reusable, which means operations may modify its value.

import { Int64 } from "int64-napi";

const i64 = new Int64(1);
const n1 = i64.add(1).multiply(3).subtract(3).divide(3).toDecimal(); // "1"

i64.set("0xFFFF000000000000");
const n2 = i64.shiftLeft(8).shiftRight(56).toHex(true); // "0xffffffffffffffff"

i64.set("0xFFFF000000000000");
const n3 = i64.shiftLeft(8).shiftRightUnsigned(56).toHex(true); // "0x00000000000000ff"

i64.set("0x000000010001");
const n4 = i64.rotateRight(8).toHex(true); // "0x0100000000000100"

i64.set("0x0000FFFFFFFF0000");
const n51 = i64.toHex(true); // "0x0000ffffffff0000"
const n52 = i64.toHex(); // "ffffffff0000"
const n53 = i64.toDecimal() + 1; // "2814749766451201"
const n54 = i64.toNumber() + 1; // 281474976645121

To clone an Int64 instance.

const i64_2 = i64.clone();

License

MIT