How to use the jsbi.BigInt function in jsbi

To help you get started, we’ve selected a few jsbi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github amzn / ion-js / test / IonDecimal.ts View on Github external
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()');
    }
github amzn / ion-js / test / IonDecimal.ts View on Github external
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()');
github amzn / ion-js / test / IonBinaryWriter.ts View on Github external
        instructions: (writer) => writer.writeInt(JSBI.BigInt('0')),
        expected: [0x20]
github amzn / ion-js / test / IonBinaryWriter.ts View on Github external
        instructions: (writer) => writer.writeInt(JSBI.BigInt('-12345678901234567890')),
        expected: [0x38, 0xab, 0x54, 0xa9, 0x8c, 0xeb, 0x1f, 0x0a, 0xd2]
github amzn / ion-js / test / IonDecimal.ts View on Github external
decimalFromNumberNumberTests.forEach(({coefficient, exponent}) => {
                let isNegative = coefficient < 0 || Object.is(-0, coefficient);
                let bigIntCoefficient = JSBI.BigInt(coefficient);
                decimalConstructorTest(bigIntCoefficient, exponent, isNegative);
            });
        });
github GoogleChromeLabs / babel-plugin-transform-jsbi-to-bigint / test / fixtures / short-import-specifier / input.js View on Github external
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'));
github amzn / ion-js / src / JsbiSupport.ts View on Github external
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;
    }

jsbi

JSBI is a pure-JavaScript implementation of [the ECMAScript BigInt proposal](https://tc39.es/proposal-bigint/), which officially became a part of the JavaScript language in ES2020.

Apache-2.0
Latest version published 3 years ago

Package Health Score

77 / 100
Full package analysis

Similar packages