Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static toUnsignedIntBytes(value: JSBI): Uint8Array {
// Remove the sign if negative
if (JsbiSupport.isNegative(value)) {
value = JSBI.unaryMinus(value);
}
let sizeInBytes = this.getUnsignedIntSizeInBytes(value);
let bytes = new Uint8Array(sizeInBytes);
for (let m = sizeInBytes - 1; m >= 0; m--) {
let lastByte = JSBI.toNumber(JSBI.bitwiseAnd(value, this.BYTE_MAX_VALUE));
value = JSBI.signedRightShift(value, this.BITS_PER_BYTE);
bytes[m] = lastByte;
}
return bytes;
}
private load_value(): void {
if (this._curr != undefined) return; // current value is already loaded
if (this.isNull()) return;
switch (this._raw_type) {
case IonBinary.TB_BOOL:
break;
case IonBinary.TB_INT:
this._curr = this._readIntegerMagnitude();
break;
case IonBinary.TB_NEG_INT:
this._curr = JSBI.unaryMinus(this._readIntegerMagnitude());
break;
case IonBinary.TB_FLOAT:
this._curr = this.read_binary_float();
break;
case IonBinary.TB_DECIMAL:
if (this._len === 0) {
this._curr = Decimal.ZERO;
} else {
this._curr = this.read_decimal_value();
}
break;
case IonBinary.TB_TIMESTAMP:
this._curr = this.read_timestamp_value();
break;
case IonBinary.TB_SYMBOL:
this._curr = this.readUnsignedIntAsNumber();
private static readDecimalValueFrom(input: BinarySpan, numberOfBytes: number): Decimal {
// Decimal representations have two components: exponent (a VarInt) and coefficient (an Int).
// The decimal’s value is: coefficient * 10 ^ exponent
let initialPosition = input.position();
let exponent: number = ParserBinaryRaw._readVarSignedIntFrom(input);
let numberOfExponentBytes = input.position() - initialPosition;
let numberOfCoefficientBytes = numberOfBytes - numberOfExponentBytes;
let signedInt = ParserBinaryRaw._readSignedIntFrom(input, numberOfCoefficientBytes);
let isNegative = signedInt.isNegative;
let coefficient = isNegative ? JSBI.unaryMinus(signedInt.magnitude) : signedInt.magnitude;
return Decimal._fromBigIntCoefficient(
isNegative,
coefficient,
exponent
);
}
JSBI.BigInt('00034');
const JSBigInt = JSBI.BigInt;
JSBigInt(34);
const JSBigInt2 = JSBI['BigInt'];
JSBigInt2(56);
const JSBIadd = JSBI.add;
JSBIadd(7, 8);
JSBI.add(a, b);
JSBI.subtract(a, b);
JSBI.multiply(a, b);
JSBI.divide(a, b);
JSBI.remainder(a, b);
JSBI.exponentiate(a, b);
const c = JSBI.unaryMinus(a);
const d = JSBI.bitwiseNot(a);
JSBI.leftShift(a, b);
JSBI.signedRightShift(a, b);
JSBI.bitwiseAnd(a, b);
JSBI.bitwiseOr(a, b);
JSBI.bitwiseXor(a, b);
JSBI.equal(a, b);
JSBI.notEqual(a, b);
JSBI.lessThan(a, b);
JSBI.lessThanOrEqual(a, b);
JSBI.greaterThan(a, b);
JSBI.greaterThanOrEqual(a, b);
JSBI.EQ(a, b);
JSBI.NE(a, b);
public static bigIntFromString(text: string): JSBI {
let isNegative = false;
let magnitudeText = text.trimLeft();
if (text.startsWith('-')) {
isNegative = true;
magnitudeText = text.substring(1);
}
let bigInt = JSBI.BigInt(magnitudeText);
if (isNegative) {
bigInt = JSBI.unaryMinus(bigInt);
}
return bigInt;
}