How to use the big-integer.prototype function in big-integer

To help you get started, we’ve selected a few big-integer 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 iden3 / snarkjs / src / bigint.js View on Github external
return this == b;
    };
    wBigInt.prototype.eq = wBigInt.prototype.equals;

    wBigInt.prototype.neq = function(b) {
        return this != b;
    };

    wBigInt.prototype.toJSNumber = function() {
        return Number(this);
    };


} else {

    var oldProto = bigInt.prototype;
    wBigInt = function(a) {
        if ((typeof a == "string") && (a.slice(0,2) == "0x")) {
            return bigInt(a.slice(2), 16);
        } else {
            return bigInt(a);
        }
    };
    wBigInt.one = bigInt.one;
    wBigInt.zero = bigInt.zero;
    wBigInt.prototype = oldProto;

    wBigInt.prototype.div = function(c) {
        return this.divide(c);
    };

    // Affine
github noobaa / noobaa-core / src / util / size_utils.js View on Github external
// 'used_reduced',
    'free',
    'reserved',
    'unavailable_free',
    'unavailable_used',
    'limit',
    'alloc',
    'real',
];

BigInteger.PETABYTE = new BigInteger(PETABYTE);

// We are overriding BigInteger.prototype.toJSON to make sure that JSON.stringify({ size: bigint }) will behave nicely
// however BigInteger creates 3 prototypes internally (Integer, SmallInteger, BigInteger)
// and writes the 'toJSON' property explicitly for all of them, we have to overwrite all 3.
const IntegerPrototype = BigInteger.prototype;
const BigIntegerPrototype = Object.getPrototypeOf(BigInteger.PETABYTE.multiply(BigInteger.PETABYTE));
const SmallIntegerPrototype = Object.getPrototypeOf(BigInteger.zero);
IntegerPrototype.toJSON = bigint_to_json_method;
BigIntegerPrototype.toJSON = bigint_to_json_method;
SmallIntegerPrototype.toJSON = bigint_to_json_method;

/**
 * @this {BigInteger}
 */
function bigint_to_json_method() {
    return bigint_to_json(this);
}

/**
 * take a BigInteger object and convert to json {peta:.., n: ..} format if needed
 */