0.1.0 • Published 4 years ago

@modern-dev/jslong v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

jslong

Build Status codecov npm NPM

The jslong - is a pure JavaScript implementation of Long class for representing a 64-bit two's-complement integer value.

$ npm install -save @modern-dev/jslong

:clipboard: Usage

import { Long } from '@modern-dev/jslong';

const val = Long.getMinValue().subtract(Long.fromInt(1024)).toString(16);
console.log(val); // '7ffffffffffffc00'

:mortar_board: API Reference

Constructor

/**
 * @param {number} low  The low (signed) 32 bits of the long.
 * @param {number} high  The high (signed) 32 bits of the long.
 */
constructor(low: number, high: number)

Methods

Method signatureDescription
toInt(): numberThe value, assuming it is a 32-bit integer.
toNumber(): numberThe closest floating-point representation to this value.
isSafeInteger(): booleanif can be exactly represented using number (i.e. abs(value) < 2^53).
toString(radix?: number): stringThe textual representation of this value.
getHighBits(): numberThe high 32-bits as a signed value.
getLowBits(): numberThe low 32-bits as a signed value.
getLowBitsUnsigned(): numberThe low 32-bits as an unsigned value.
getNumBitsAbs(): numberReturns the number of bits needed to represent the absolute value of this Long.
isZero(): booleanWhether this value is zero.
isNegative(): booleanWhether this value is negative.
isOdd(): booleanWhether this value is odd.
equals(other: Long): booleanWhether this Long equals the other.
notEquals(other: Long): booleanWhether this Long does not equal the other.
lessThan(other: Long): booleanWhether this Long is less than the other.
lessThanOrEqual(other: Long): booleanWhether this Long is less than or equal to the other.
greaterThan(other: Long): booleanWhether this Long is greater than the other.
greaterThanOrEqual(other: Long): booleanWhether this Long is greater than or equal to the other.
compare(other: Long): number0 if they are the same, 1 if the this is greater, and -1 if the given one is greater.
negate(): LongThe negation of this value.
add(other: Long): LongThe sum of this and the given Long.
subtract(other: Long): LongThe difference of this and the given Long.
multiply(other: Long): LongThe product of this and the other.
div(other: Long): LongThis Long divided by the given one.
modulo(other: Long): LongThis Long modulo the given one.
not(): LongThe bitwise-NOT of this value.
and(other: Long): LongThe bitwise-AND of this and the other.
or(other: Long): LongThe bitwise-OR of this and the other.
xor(other: Long): LongThe bitwise-XOR of this and the other.
shiftLeft(numBits: number): LongThis shifted to the left by the given amount.
shiftRight(numBits: number): LongThis shifted to the right by the given amount.
shiftRightUnsigned(numBits: number): LongThis shifted to the right by the given amount, with zeros placed into the new leading bits.
static fromInt(value: number): LongThe corresponding Long value.
static fromNumber(value: number): LongThe corresponding Long value.
static fromBits(lowBits: number, highBits: number): LongThe corresponding Long value.
static fromString(str: string, opt_radix?: number): LongThe corresponding Long value.
static isStringInRange(str: string, opt_radix: number): booleanWhether the string is within the range of a Long.

:green_book: License

Licensed under the Apache License 2.0.

Based on the Long implementation for Google's Closure Library.

Copyright 2009 The Closure Library Authors. All Rights Reserved. Copyright (c) 2020 Bohdan Shtepan


modern-dev.com  ·  GitHub @virtyaluk  ·  Twitter @virtyaluk