Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function test(decimalString,
expectedCoefficient,
expectedExponent,
expectedNumberValue,
expectedToString) {
let decimal = ion.Decimal.parse(decimalString);
assert.deepEqual(decimal.getCoefficient(), JSBI.BigInt(expectedCoefficient), '_getCoefficient()');
assert.equal(decimal.isNegative(), Object.is(Number(expectedCoefficient), -0) || JsbiSupport.isNegative(JSBI.BigInt(expectedCoefficient)), 'coefficient sign');
assert.equal(decimal.getExponent(), expectedExponent, '_getExponent()');
assert.equal(util._sign(decimal.getExponent()), util._sign(expectedExponent), 'exponent sign');
assert.equal(decimal.isNegative(), decimalString.trim()[0] === '-', 'isNegative()');
if (expectedNumberValue instanceof Array) {
if (expectedNumberValue.length !== 2) {
throw new Error(`Expected number value must be size two ${expectedNumberValue}`);
}
const decNumberValue = decimal.numberValue();
assert.isAtLeast(decNumberValue, expectedNumberValue[0], `numberValue() not in range ${expectedNumberValue}`);
assert.isAtMost(decNumberValue, expectedNumberValue[1], `numberValue() not in range ${expectedNumberValue}`);
} else {
assert.equal(decimal.numberValue(), expectedNumberValue, 'numberValue()');
}
function test(decimalString,
expectedCoefficient,
expectedExponent,
expectedNumberValue,
expectedToString) {
let decimal = ion.Decimal.parse(decimalString);
assert.deepEqual(decimal.getCoefficient(), JSBI.BigInt(expectedCoefficient), '_getCoefficient()');
assert.equal(decimal.isNegative(), Object.is(Number(expectedCoefficient), -0) || JsbiSupport.isNegative(JSBI.BigInt(expectedCoefficient)), 'coefficient sign');
assert.equal(decimal.getExponent(), expectedExponent, '_getExponent()');
assert.equal(util._sign(decimal.getExponent()), util._sign(expectedExponent), 'exponent sign');
assert.equal(decimal.isNegative(), decimalString.trim()[0] === '-', 'isNegative()');
if (expectedNumberValue instanceof Array) {
if (expectedNumberValue.length !== 2) {
throw new Error(`Expected number value must be size two ${expectedNumberValue}`);
}
const decNumberValue = decimal.numberValue();
assert.isAtLeast(decNumberValue, expectedNumberValue[0], `numberValue() not in range ${expectedNumberValue}`);
assert.isAtMost(decNumberValue, expectedNumberValue[1], `numberValue() not in range ${expectedNumberValue}`);
} else {
assert.equal(decimal.numberValue(), expectedNumberValue, 'numberValue()');
instructions: (writer) => writer.writeInt(JSBI.BigInt('0')),
expected: [0x20]
instructions: (writer) => writer.writeInt(JSBI.BigInt('-12345678901234567890')),
expected: [0x38, 0xab, 0x54, 0xa9, 0x8c, 0xeb, 0x1f, 0x0a, 0xd2]
decimalFromNumberNumberTests.forEach(({coefficient, exponent}) => {
let isNegative = coefficient < 0 || Object.is(-0, coefficient);
let bigIntCoefficient = JSBI.BigInt(coefficient);
decimalConstructorTest(bigIntCoefficient, exponent, isNegative);
});
});
JSBI.greaterThan(a, b);
JSBI.greaterThanOrEqual(a, b);
JSBI.EQ(a, b);
JSBI.NE(a, b);
JSBI.LT(a, b);
JSBI.LE(a, b);
JSBI.GT(a, b);
JSBI.GE(a, b);
a.toString();
JSBI.toNumber(a);
a instanceof JSBI;
JSBI.asIntN(64, JSBI.BigInt('42'));
JSBI.asUintN(64, JSBI.BigInt('42'));
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;
}