61 lines
1.7 KiB
JavaScript
61 lines
1.7 KiB
JavaScript
"use strict";
|
|
// Copyright (C) 2016 Dmitry Chestnykh
|
|
// MIT License. See LICENSE file for details.
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
/**
|
|
* Package int provides helper functions for integerss.
|
|
*/
|
|
// Shim using 16-bit pieces.
|
|
function imulShim(a, b) {
|
|
var ah = (a >>> 16) & 0xffff, al = a & 0xffff;
|
|
var bh = (b >>> 16) & 0xffff, bl = b & 0xffff;
|
|
return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0) | 0);
|
|
}
|
|
/** 32-bit integer multiplication. */
|
|
// Use system Math.imul if available, otherwise use our shim.
|
|
exports.mul = Math.imul || imulShim;
|
|
/** 32-bit integer addition. */
|
|
function add(a, b) {
|
|
return (a + b) | 0;
|
|
}
|
|
exports.add = add;
|
|
/** 32-bit integer subtraction. */
|
|
function sub(a, b) {
|
|
return (a - b) | 0;
|
|
}
|
|
exports.sub = sub;
|
|
/** 32-bit integer left rotation */
|
|
function rotl(x, n) {
|
|
return x << n | x >>> (32 - n);
|
|
}
|
|
exports.rotl = rotl;
|
|
/** 32-bit integer left rotation */
|
|
function rotr(x, n) {
|
|
return x << (32 - n) | x >>> n;
|
|
}
|
|
exports.rotr = rotr;
|
|
function isIntegerShim(n) {
|
|
return typeof n === "number" && isFinite(n) && Math.floor(n) === n;
|
|
}
|
|
/**
|
|
* Returns true if the argument is an integer number.
|
|
*
|
|
* In ES2015, Number.isInteger.
|
|
*/
|
|
exports.isInteger = Number.isInteger || isIntegerShim;
|
|
/**
|
|
* Math.pow(2, 53) - 1
|
|
*
|
|
* In ES2015 Number.MAX_SAFE_INTEGER.
|
|
*/
|
|
exports.MAX_SAFE_INTEGER = 9007199254740991;
|
|
/**
|
|
* Returns true if the argument is a safe integer number
|
|
* (-MIN_SAFE_INTEGER < number <= MAX_SAFE_INTEGER)
|
|
*
|
|
* In ES2015, Number.isSafeInteger.
|
|
*/
|
|
exports.isSafeInteger = function (n) {
|
|
return exports.isInteger(n) && (n >= -exports.MAX_SAFE_INTEGER && n <= exports.MAX_SAFE_INTEGER);
|
|
};
|
|
//# sourceMappingURL=int.js.map
|