all files / lib/ OverflowLong.js

100% Statements 52/52
100% Branches 22/22
100% Functions 9/9
100% Lines 49/49
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                1862× 1862× 683× 683×   1179× 1028× 1028× 864×     164× 164×       151× 151× 111×     40× 40×     1179×   54×   51× 51× 51× 1501×   51×     1924× 1923× 1922×      
"use strict";
var OverflowLong = (function () {
    function OverflowLong(_value, MIN_SAFE_VALUE, MAX_SAFE_VALUE) {
        if (_value === void 0) { _value = 0; }
        if (MIN_SAFE_VALUE === void 0) { MIN_SAFE_VALUE = Number.MIN_SAFE_INTEGER; }
        if (MAX_SAFE_VALUE === void 0) { MAX_SAFE_VALUE = Number.MAX_SAFE_INTEGER; }
        this._value = _value;
        this.MIN_SAFE_VALUE = MIN_SAFE_VALUE;
        this.MAX_SAFE_VALUE = MAX_SAFE_VALUE;
        this._value = this.valCheck(_value);
    }
    Object.defineProperty(OverflowLong.prototype, "value", {
        get: function () {
            return this._value;
        },
        enumerable: true,
        configurable: true
    });
    OverflowLong.prototype.valueOf = function () {
        return this._value;
    };
    OverflowLong.prototype.plus = function (v) {
        v = this.valCheck(v);
        if ((this._value >= 0 && v <= 0) || (this._value <= 0 && v >= 0)) {
            this._value = this._value + v;
            return this;
        }
        if (v >= 0) {
            var diffToMax = this.MAX_SAFE_VALUE - this._value;
            if (diffToMax >= v) {
                this._value = this._value + v;
            }
            else {
                this._value = this.MIN_SAFE_VALUE;
                this.plus(v - diffToMax - 1);
            }
        }
        else {
            var diffToMin = this.MIN_SAFE_VALUE - this._value;
            if (diffToMin <= v) {
                this._value = this._value + v;
            }
            else {
                this._value = this.MAX_SAFE_VALUE;
                this.plus(v - diffToMin + 1);
            }
        }
        return this;
    };
    OverflowLong.prototype.minus = function (v) {
        return this.plus(v * -1);
    };
    OverflowLong.prototype.times = function (v) {
        v = this.valCheck(v);
        var v2 = this._value;
        for (var i = 1; i < v; i++) {
            this.plus(v2);
        }
        return this;
    };
    OverflowLong.prototype.divide = function (v) {
        this._value = this.valCheck((this._value / this.valCheck(v)));
        return this;
    };
    OverflowLong.prototype.valCheck = function (v) {
        if (v > this.MAX_SAFE_VALUE)
            throw new RangeError("The given long greater than the MAX_SAFE_VALUE.");
        if (v < this.MIN_SAFE_VALUE)
            throw new RangeError("The given long less than the MIN_SAFE_VALUE.");
        return parseInt(v);
    };
    return OverflowLong;
}());
exports.OverflowLong = OverflowLong;
//# sourceMappingURL=OverflowLong.js.map