(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular-ru/cdk/utils')) :
    typeof define === 'function' && define.amd ? define('@angular-ru/cdk/big-decimal', ['exports', '@angular-ru/cdk/utils'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['angular-ru'] = global['angular-ru'] || {}, global['angular-ru'].cdk = global['angular-ru'].cdk || {}, global['angular-ru'].cdk['big-decimal'] = {}), global['angular-ru'].cdk.utils));
}(this, (function (exports, utils) { 'use strict';

    /*! *****************************************************************************
    Copyright (c) Microsoft Corporation.

    Permission to use, copy, modify, and/or distribute this software for any
    purpose with or without fee is hereby granted.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
    REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
    OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    PERFORMANCE OF THIS SOFTWARE.
    ***************************************************************************** */
    /* global Reflect, Promise */
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b)
                if (Object.prototype.hasOwnProperty.call(b, p))
                    d[p] = b[p]; };
        return extendStatics(d, b);
    };
    function __extends(d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    }
    var __assign = function () {
        __assign = Object.assign || function __assign(t) {
            for (var s, i = 1, n = arguments.length; i < n; i++) {
                s = arguments[i];
                for (var p in s)
                    if (Object.prototype.hasOwnProperty.call(s, p))
                        t[p] = s[p];
            }
            return t;
        };
        return __assign.apply(this, arguments);
    };
    function __rest(s, e) {
        var t = {};
        for (var p in s)
            if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
                t[p] = s[p];
        if (s != null && typeof Object.getOwnPropertySymbols === "function")
            for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
                if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                    t[p[i]] = s[p[i]];
            }
        return t;
    }
    function __decorate(decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
            r = Reflect.decorate(decorators, target, key, desc);
        else
            for (var i = decorators.length - 1; i >= 0; i--)
                if (d = decorators[i])
                    r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    }
    function __param(paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); };
    }
    function __metadata(metadataKey, metadataValue) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
            return Reflect.metadata(metadataKey, metadataValue);
    }
    function __awaiter(thisArg, _arguments, P, generator) {
        function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) { try {
                step(generator.next(value));
            }
            catch (e) {
                reject(e);
            } }
            function rejected(value) { try {
                step(generator["throw"](value));
            }
            catch (e) {
                reject(e);
            } }
            function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments || [])).next());
        });
    }
    function __generator(thisArg, body) {
        var _ = { label: 0, sent: function () { if (t[0] & 1)
                throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
        return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
        function verb(n) { return function (v) { return step([n, v]); }; }
        function step(op) {
            if (f)
                throw new TypeError("Generator is already executing.");
            while (_)
                try {
                    if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
                        return t;
                    if (y = 0, t)
                        op = [op[0] & 2, t.value];
                    switch (op[0]) {
                        case 0:
                        case 1:
                            t = op;
                            break;
                        case 4:
                            _.label++;
                            return { value: op[1], done: false };
                        case 5:
                            _.label++;
                            y = op[1];
                            op = [0];
                            continue;
                        case 7:
                            op = _.ops.pop();
                            _.trys.pop();
                            continue;
                        default:
                            if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
                                _ = 0;
                                continue;
                            }
                            if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
                                _.label = op[1];
                                break;
                            }
                            if (op[0] === 6 && _.label < t[1]) {
                                _.label = t[1];
                                t = op;
                                break;
                            }
                            if (t && _.label < t[2]) {
                                _.label = t[2];
                                _.ops.push(op);
                                break;
                            }
                            if (t[2])
                                _.ops.pop();
                            _.trys.pop();
                            continue;
                    }
                    op = body.call(thisArg, _);
                }
                catch (e) {
                    op = [6, e];
                    y = 0;
                }
                finally {
                    f = t = 0;
                }
            if (op[0] & 5)
                throw op[1];
            return { value: op[0] ? op[1] : void 0, done: true };
        }
    }
    var __createBinding = Object.create ? (function (o, m, k, k2) {
        if (k2 === undefined)
            k2 = k;
        Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
    }) : (function (o, m, k, k2) {
        if (k2 === undefined)
            k2 = k;
        o[k2] = m[k];
    });
    function __exportStar(m, o) {
        for (var p in m)
            if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
                __createBinding(o, m, p);
    }
    function __values(o) {
        var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
        if (m)
            return m.call(o);
        if (o && typeof o.length === "number")
            return {
                next: function () {
                    if (o && i >= o.length)
                        o = void 0;
                    return { value: o && o[i++], done: !o };
                }
            };
        throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
    }
    function __read(o, n) {
        var m = typeof Symbol === "function" && o[Symbol.iterator];
        if (!m)
            return o;
        var i = m.call(o), r, ar = [], e;
        try {
            while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
                ar.push(r.value);
        }
        catch (error) {
            e = { error: error };
        }
        finally {
            try {
                if (r && !r.done && (m = i["return"]))
                    m.call(i);
            }
            finally {
                if (e)
                    throw e.error;
            }
        }
        return ar;
    }
    /** @deprecated */
    function __spread() {
        for (var ar = [], i = 0; i < arguments.length; i++)
            ar = ar.concat(__read(arguments[i]));
        return ar;
    }
    /** @deprecated */
    function __spreadArrays() {
        for (var s = 0, i = 0, il = arguments.length; i < il; i++)
            s += arguments[i].length;
        for (var r = Array(s), k = 0, i = 0; i < il; i++)
            for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
                r[k] = a[j];
        return r;
    }
    function __spreadArray(to, from, pack) {
        if (pack || arguments.length === 2)
            for (var i = 0, l = from.length, ar; i < l; i++) {
                if (ar || !(i in from)) {
                    if (!ar)
                        ar = Array.prototype.slice.call(from, 0, i);
                    ar[i] = from[i];
                }
            }
        return to.concat(ar || Array.prototype.slice.call(from));
    }
    function __await(v) {
        return this instanceof __await ? (this.v = v, this) : new __await(v);
    }
    function __asyncGenerator(thisArg, _arguments, generator) {
        if (!Symbol.asyncIterator)
            throw new TypeError("Symbol.asyncIterator is not defined.");
        var g = generator.apply(thisArg, _arguments || []), i, q = [];
        return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
        function verb(n) { if (g[n])
            i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
        function resume(n, v) { try {
            step(g[n](v));
        }
        catch (e) {
            settle(q[0][3], e);
        } }
        function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
        function fulfill(value) { resume("next", value); }
        function reject(value) { resume("throw", value); }
        function settle(f, v) { if (f(v), q.shift(), q.length)
            resume(q[0][0], q[0][1]); }
    }
    function __asyncDelegator(o) {
        var i, p;
        return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
        function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
    }
    function __asyncValues(o) {
        if (!Symbol.asyncIterator)
            throw new TypeError("Symbol.asyncIterator is not defined.");
        var m = o[Symbol.asyncIterator], i;
        return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
        function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
        function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
    }
    function __makeTemplateObject(cooked, raw) {
        if (Object.defineProperty) {
            Object.defineProperty(cooked, "raw", { value: raw });
        }
        else {
            cooked.raw = raw;
        }
        return cooked;
    }
    ;
    var __setModuleDefault = Object.create ? (function (o, v) {
        Object.defineProperty(o, "default", { enumerable: true, value: v });
    }) : function (o, v) {
        o["default"] = v;
    };
    function __importStar(mod) {
        if (mod && mod.__esModule)
            return mod;
        var result = {};
        if (mod != null)
            for (var k in mod)
                if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
                    __createBinding(result, mod, k);
        __setModuleDefault(result, mod);
        return result;
    }
    function __importDefault(mod) {
        return (mod && mod.__esModule) ? mod : { default: mod };
    }
    function __classPrivateFieldGet(receiver, state, kind, f) {
        if (kind === "a" && !f)
            throw new TypeError("Private accessor was defined without a getter");
        if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
            throw new TypeError("Cannot read private member from an object whose class did not declare it");
        return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
    }
    function __classPrivateFieldSet(receiver, state, value, kind, f) {
        if (kind === "m")
            throw new TypeError("Private method is not writable");
        if (kind === "a" && !f)
            throw new TypeError("Private accessor was defined without a setter");
        if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
            throw new TypeError("Cannot write private member to an object whose class did not declare it");
        return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
    }

    var DEFAULT_DIGITS = 3;
    var EXPONENTIAL_PARTS_LENGTH = 2;
    var NUMBER_SYSTEM = 10;
    var DEFAULT_PRECISSION = 8;
    var PRECISSION_SECOND = 2;

    function trim(number) {
        var _a, _b;
        var split = (_a = number.split('.')) !== null && _a !== void 0 ? _a : [];
        var parts = removeZerosAtTheBeginning(split);
        if (utils.isNil(parts[1])) {
            return (_b = parts[0]) !== null && _b !== void 0 ? _b : '';
        }
        else {
            return parts[0] + "." + parts[1];
        }
    }
    // eslint-disable-next-line max-lines-per-function, complexity
    function add(inputA, inputB) {
        if (inputB === void 0) { inputB = '0'; }
        var a = inputA;
        var b = inputB;
        var neg = 0;
        var ind = -1;
        // check for negatives
        if (inputA[0] === '-') {
            neg++;
            ind = 1;
            a = inputA.substring(1);
        }
        if (inputB[0] === '-') {
            neg++;
            ind = EXPONENTIAL_PARTS_LENGTH;
            b = inputB.substring(1);
        }
        var padResult = pad(trim(a), trim(b));
        a = padResult[0];
        b = padResult[1];
        if (neg === 1) {
            if (ind === 1) {
                a = compliment(a);
            }
            else {
                b = compliment(b);
            }
        }
        var res = addCore(a, b);
        if (!neg) {
            return trim(res);
        }
        else if (neg === EXPONENTIAL_PARTS_LENGTH) {
            return "-" + trim(res);
        }
        else {
            if (a.length < res.length) {
                return trim(res.substring(1));
            }
            else {
                return "-" + trim(compliment(res));
            }
        }
    }
    // eslint-disable-next-line max-lines-per-function, complexity
    function pad(inputA, inputB) {
        var _a, _b, _c, _d;
        var partsA = inputA.split('.');
        var partsB = inputB.split('.');
        // pad integral part
        var length1 = (_b = (_a = partsA[0]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
        var length2 = (_d = (_c = partsB[0]) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0;
        var larger = Math.abs(length1 - length2);
        if (length1 > length2) {
            partsB[0] = getIntegralPart(partsB, larger);
        }
        else {
            partsA[0] = getIntegralPart(partsA, larger);
        }
        // pad fractional part
        length1 = utils.checkValueIsFilled(partsA[1]) ? partsA[1].length : 0;
        length2 = utils.checkValueIsFilled(partsB[1]) ? partsB[1].length : 0;
        larger = Math.abs(length1 - length2);
        if (length1 || length2) {
            if (length1 > length2) {
                partsB[1] = getFractionalPart(partsB, larger);
            }
            else {
                partsA[1] = getFractionalPart(partsA, larger);
            }
        }
        var a = getPadFormat(partsA);
        var b = getPadFormat(partsB);
        return [a, b];
    }
    function compliment(num) {
        var _a;
        var s = '';
        var part = num.split('.')[1];
        var ld = utils.checkValueIsFilled(part) ? part.length : 0;
        for (var i = 0; i < num.length; i++) {
            s += getPreparedDigit((_a = num[i]) !== null && _a !== void 0 ? _a : '');
        }
        var one = ld > 0 ? "0." + new Array(ld).join('0') + "1" : '1';
        return addCore(s, one);
    }
    function getPreparedDigit(char) {
        var isDigit = char >= '0' && char <= '9';
        if (isDigit) {
            // eslint-disable-next-line @typescript-eslint/no-magic-numbers
            return 9 - parseInt(char);
        }
        else {
            return char;
        }
    }
    function getIntegralPart(parts, larger) {
        return new Array(larger + 1).join('0') + (utils.checkValueIsFilled(parts[0]) ? parts[0] : '');
    }
    function getFractionalPart(parts, larger) {
        return (utils.checkValueIsFilled(parts[1]) ? parts[1] : '') + new Array(larger + 1).join('0');
    }
    function getPadFormat(parts) {
        return parts[0] + (utils.checkValueIsFilled(parts[1]) ? "." + parts[1] : '');
    }
    function removeZerosAtTheBeginning(parts) {
        var result = __spreadArray([], __read(parts), false);
        if (utils.checkValueIsEmpty(result[0])) {
            result[0] = '0';
        }
        while (result[0][0] === '0' && result[0].length > 1) {
            result[0] = result[0].substring(1);
        }
        return result;
    }
    function addCore(inputA, inputB) {
        var _a, _b;
        var parts = pad(inputA, inputB);
        var a = (_a = parts[0]) !== null && _a !== void 0 ? _a : '';
        var b = (_b = parts[1]) !== null && _b !== void 0 ? _b : '';
        var calculateResult = calculateCarryAndSum(a, b);
        var sum = calculateResult.sum;
        var carry = calculateResult.carry;
        return carry ? carry.toString() + sum : sum;
    }
    function calculateCarryAndSum(a, b) {
        var _a, _b;
        var sum = '';
        var carry = 0;
        for (var i = a.length - 1; i >= 0; i--) {
            if (a[i] === '.') {
                sum = "." + sum;
                continue;
            }
            var temp = parseInt((_a = a[i]) !== null && _a !== void 0 ? _a : '') + parseInt((_b = b[i]) !== null && _b !== void 0 ? _b : '') + carry;
            sum = (temp % NUMBER_SYSTEM) + sum;
            carry = Math.floor(temp / NUMBER_SYSTEM);
        }
        return { sum: sum, carry: carry };
    }

    function compareTo(a, b) {
        var onlyOneNegative = compareIfOnlyOneNegative(a, b);
        if (utils.isNotNil(onlyOneNegative)) {
            return onlyOneNegative;
        }
        var bothNegative = compareIfBothNegative(a, b);
        if (utils.isNotNil(bothNegative)) {
            return bothNegative;
        }
        var bothPositive = compareIfBothPositive(a, b);
        if (utils.isNotNil(bothPositive)) {
            return bothPositive;
        }
        return 0;
    }
    function compareIfOnlyOneNegative(a, b) {
        var result = null;
        if (a[0] === '-' && b[0] !== '-') {
            result = -1;
        }
        if (a[0] !== '-' && b[0] === '-') {
            result = 1;
        }
        return result;
    }
    function compareIfBothNegative(inputA, inputB) {
        if (inputA[0] !== '-' || inputB[0] !== '-') {
            return null;
        }
        var a = inputA.substr(1);
        var b = inputB.substr(1);
        var compareModulesResult = compareNumberModules(a, b);
        if (compareModulesResult === 1) {
            return -1;
        }
        if (compareModulesResult === -1) {
            return 1;
        }
        return compareModulesResult;
    }
    function compareIfBothPositive(a, b) {
        return compareNumberModules(a, b);
    }
    function compareNumberModules(inputA, inputB) {
        var _a, _b;
        var a = pad(inputA, inputB)[0];
        var b = pad(inputA, inputB)[1];
        if (a.localeCompare(b) === 0) {
            return 0;
        }
        for (var i = 0; i < a.length; i++) {
            var compareDigitsResult = compareDigits((_a = a[i]) !== null && _a !== void 0 ? _a : '', (_b = b[i]) !== null && _b !== void 0 ? _b : '');
            if (compareDigitsResult === 0) {
                continue;
            }
            else {
                return compareDigitsResult;
            }
        }
        return 0;
    }
    function compareDigits(a, b) {
        if (a === b) {
            return 0;
        }
        if (a > b) {
            return 1;
        }
        return -1;
    }

    /**
     *
     * @param input the number to round
     * @param n precision
     * @param mode Rounding Mode
     */
    function roundOff(input, n, mode /* HALF_EVEN */) {
        if (n === void 0) { n = 0; }
        if (mode === void 0) { mode = 4; }
        var _a, _b, _c, _d;
        if (mode === 6 /* UNNECESSARY */) {
            throw new Error('UNNECESSARY Rounding Mode has not yet been implemented');
        }
        if (typeof input == 'number')
            input = input.toString();
        var neg = false;
        if (input[0] === '-') {
            neg = true;
            input = input.substring(1);
        }
        var parts = input.split('.'), partInt = parts[0], partDec = parts[1];
        //handle case of -ve n: roundOff(12564,-2)=12600
        if (n < 0) {
            n = -n;
            if (((_a = partInt === null || partInt === void 0 ? void 0 : partInt.length) !== null && _a !== void 0 ? _a : 0) <= n)
                return '0';
            else {
                var prefix = partInt === null || partInt === void 0 ? void 0 : partInt.substr(0, ((_b = partInt === null || partInt === void 0 ? void 0 : partInt.length) !== null && _b !== void 0 ? _b : 0) - n);
                input = prefix + '.' + (partInt === null || partInt === void 0 ? void 0 : partInt.substr(((_c = partInt === null || partInt === void 0 ? void 0 : partInt.length) !== null && _c !== void 0 ? _c : 0) - n)) + partDec;
                prefix = roundOff(input, 0, mode);
                return (neg ? '-' : '') + prefix + new Array(n + 1).join('0');
            }
        }
        // handle case when integer output is desired
        if (n == 0) {
            if (greaterThanFive(parts[1], partInt, neg, mode)) {
                return (neg ? '-' : '') + increment(partInt);
            }
            return (neg ? '-' : '') + partInt;
        }
        // handle case when n>0
        if (!parts[1]) {
            return (neg ? '-' : '') + partInt + '.' + new Array(n + 1).join('0');
        }
        else if (parts[1].length < n) {
            return (neg ? '-' : '') + partInt + '.' + parts[1] + new Array(n - parts[1].length + 1).join('0');
        }
        partDec = parts[1].substring(0, n);
        var rem = parts[1].substring(n);
        if (rem && greaterThanFive(rem, partDec, neg, mode)) {
            partDec = increment(partDec);
            if (partDec.length > n) {
                return (neg ? '-' : '') + increment(partInt, parseInt((_d = partDec[0]) !== null && _d !== void 0 ? _d : '')) + '.' + partDec.substring(1);
            }
        }
        return (neg ? '-' : '') + partInt + '.' + partDec;
    }
    function greaterThanFive(part, pre, neg, mode) {
        if (!part || part === new Array(part.length + 1).join('0'))
            return false;
        // #region UP, DOWN, CEILING, FLOOR
        if (mode === 1 /* DOWN */ ||
            (!neg && mode === 2 /* FLOOR */) ||
            (neg && mode === 0 /* CEILING */))
            return false;
        if (mode === 7 /* UP */ || (neg && mode === 2 /* FLOOR */) || (!neg && mode === 0 /* CEILING */))
            return true;
        // #endregion
        // case when part !== five
        var five = '5' + new Array(part.length).join('0');
        if (part > five)
            return true;
        else if (part < five)
            return false;
        // case when part === five
        switch (mode) {
            case 3 /* HALF_DOWN */:
                return false;
            case 5 /* HALF_UP */:
                return true;
            case 4 /* HALF_EVEN */:
            default:
                return parseInt(pre[pre.length - 1]) % 2 == 1;
        }
    }
    function increment(part, c) {
        if (c === void 0) { c = 0; }
        if (!c)
            c = 1;
        if (typeof part == 'number')
            part.toString();
        var l = part.length - 1, s = '';
        for (var i = l; i >= 0; i--) {
            var x = parseInt(part[i]) + c;
            if (x == 10) {
                c = 1;
                x = 0;
            }
            else {
                c = 0;
            }
            s += x;
        }
        if (c)
            s += c;
        return s.split('').reverse().join('');
    }

    // eslint-disable-next-line max-lines-per-function,complexity,sonarjs/cognitive-complexity
    function divide(inputDividend, inputDivisor, inputPrecission) {
        if (inputPrecission === void 0) { inputPrecission = DEFAULT_PRECISSION; }
        checkDivisionByZero(inputDivisor);
        var dividend = inputDividend.toString();
        var divisor = inputDivisor.toString();
        dividend = removeTrailingZeros(dividend);
        divisor = removeTrailingZeros(divisor);
        if (dividend === '0') {
            return '0';
        }
        var isNegative = checkNegative(divisor, dividend);
        divisor = getAbsoluteValue(divisor);
        dividend = getAbsoluteValue(dividend);
        dividend = parseDividend(dividend, divisor);
        divisor = trim(divisor.replace('.', ''));
        var dl = divisor.length;
        var precission = 0;
        var quotient = '';
        var dividendBeforePoint = dividend.indexOf('.') > -1 && dividend.indexOf('.') < dl
            ? dividend.substring(0, dl + 1)
            : dividend.substring(0, dl);
        dividend =
            dividend.indexOf('.') > -1 && dividend.indexOf('.') < dl ? dividend.substring(dl + 1) : dividend.substring(dl);
        if (dividendBeforePoint.indexOf('.') > -1) {
            var shift = dividendBeforePoint.length - dividendBeforePoint.indexOf('.') - 1;
            dividendBeforePoint = dividendBeforePoint.replace('.', '');
            if (dl > dividendBeforePoint.length) {
                shift += dl - dividendBeforePoint.length;
                dividendBeforePoint = dividendBeforePoint + new Array(dl - dividendBeforePoint.length + 1).join('0');
            }
            precission = shift;
            quotient = "0." + new Array(shift).join('0');
        }
        while (precission <= inputPrecission + PRECISSION_SECOND) {
            var qt = 0;
            while (parseInt(dividendBeforePoint) >= parseInt(divisor)) {
                dividendBeforePoint = add(dividendBeforePoint, "-" + divisor);
                qt++;
            }
            quotient += qt;
            var isDividendEmpty = utils.checkValueIsEmpty(dividend);
            if (isDividendEmpty) {
                if (!precission) {
                    quotient += '.';
                }
                precission++;
                dividendBeforePoint = dividendBeforePoint + "0";
            }
            else {
                if (dividend[0] === '.') {
                    quotient += '.';
                    precission++;
                    dividend = dividend.substring(1);
                }
                dividendBeforePoint = dividendBeforePoint + dividend.substring(0, 1);
                dividend = dividend.substring(1);
            }
        }
        return (isNegative ? '-' : '') + trim(roundOff(quotient, inputPrecission));
    }
    function parseDividend(inputDividend, divisor) {
        var dividend = inputDividend;
        var ptDivisor = divisor.indexOf('.') > 0 ? divisor.length - divisor.indexOf('.') - 1 : -1;
        if (ptDivisor >= 0) {
            dividend = parseDividendByPositiveDividend(dividend, ptDivisor);
        }
        return dividend;
    }
    function parseDividendByPositiveDividend(inputDividend, ptDivisor) {
        var dividend = inputDividend;
        var ptDividend = dividend.indexOf('.') > 0 ? dividend.length - dividend.indexOf('.') - 1 : -1;
        if (ptDividend === -1) {
            dividend = trim(dividend + new Array(ptDivisor + 1).join('0'));
        }
        else {
            if (ptDivisor > ptDividend) {
                dividend = dividend.replace('.', '');
                dividend = trim(dividend + new Array(ptDivisor - ptDividend + 1).join('0'));
            }
            else if (ptDivisor < ptDividend) {
                dividend = dividend.replace('.', '');
                var i = dividend.length - ptDividend + ptDivisor;
                dividend = trim(dividend.substring(0, i) + "." + dividend.substring(i));
            }
            else if (ptDivisor === ptDividend) {
                dividend = trim(dividend.replace('.', ''));
            }
        }
        return dividend;
    }
    function removeTrailingZeros(value) {
        return value.replace(/(\.\d*?[1-9])0+$/g, '$1').replace(/\.0+$/, '');
    }
    function checkDivisionByZero(divisor) {
        if (divisor === 0 || divisor === '0') {
            throw new Error('Cannot divide by 0');
        }
    }
    function checkNegative(divisor, dividend) {
        var isNegative = false;
        if (divisor[0] === '-') {
            isNegative = !isNegative;
        }
        if (dividend[0] === '-') {
            isNegative = !isNegative;
        }
        return isNegative;
    }
    function getAbsoluteValue(value) {
        return value[0] === '-' ? value.substring(1) : value;
    }

    /* eslint-disable */
    function multiply(number1, number2) {
        var _a, _b;
        number1 = number1.toString();
        number2 = number2.toString();
        /*Filter numbers*/
        var negative = 0;
        if (number1[0] == '-') {
            negative++;
            number1 = number1.substr(1);
        }
        if (number2[0] == '-') {
            negative++;
            number2 = number2.substr(1);
        }
        number1 = trailZero(number1);
        number2 = trailZero(number2);
        var decimalLength1 = 0;
        var decimalLength2 = 0;
        if (number1.indexOf('.') != -1) {
            decimalLength1 = number1.length - number1.indexOf('.') - 1;
        }
        if (number2.indexOf('.') != -1) {
            decimalLength2 = number2.length - number2.indexOf('.') - 1;
        }
        var decimalLength = decimalLength1 + decimalLength2;
        number1 = trailZero(number1.replace('.', ''));
        number2 = trailZero(number2.replace('.', ''));
        if (number1.length < number2.length) {
            var temp = number1;
            number1 = number2;
            number2 = temp;
        }
        if (number2 == '0') {
            return '0';
        }
        /*
         * Core multiplication
         */
        var length = number2.length;
        var carry = 0;
        var positionVector = [];
        var currentPosition = length - 1;
        var result = '';
        for (var i = 0; i < length; i++) {
            positionVector[i] = number1.length - 1;
        }
        for (var i = 0; i < 2 * number1.length; i++) {
            var sum = 0;
            for (var j = number2.length - 1; j >= currentPosition && j >= 0; j--) {
                if (((_a = positionVector[j]) !== null && _a !== void 0 ? _a : 0) > -1 && ((_b = positionVector[j]) !== null && _b !== void 0 ? _b : 0) < number1.length) {
                    sum += parseInt(number1[positionVector[j]--]) * parseInt(number2[j]);
                }
            }
            sum += carry;
            carry = Math.floor(sum / 10);
            result = (sum % 10) + result;
            currentPosition--;
        }
        /*
         * Formatting result
         */
        result = trailZero(adjustDecimal(result, decimalLength));
        if (negative == 1) {
            result = '-' + result;
        }
        return result;
    }
    /*
     * Add decimal point
     */
    function adjustDecimal(number, decimal) {
        if (decimal == 0)
            return number;
        else {
            number = decimal >= number.length ? new Array(decimal - number.length + 1).join('0') + number : number;
            return number.substr(0, number.length - decimal) + '.' + number.substr(number.length - decimal, decimal);
        }
    }
    /*
     * Removes zero from front and back*/
    function trailZero(number) {
        while (number[0] == '0') {
            number = number.substr(1);
        }
        if (number.indexOf('.') != -1) {
            while (number[number.length - 1] == '0') {
                number = number.substr(0, number.length - 1);
            }
        }
        if (number == '' || number == '.') {
            number = '0';
        }
        else if (number[number.length - 1] == '.') {
            number = number.substr(0, number.length - 1);
        }
        if (number[0] == '.') {
            number = '0' + number;
        }
        return number;
    }

    function subtract(number1, number2) {
        var a = number1.toString();
        var b = number2.toString();
        b = negate(b);
        return add(a, b);
    }
    function negate(number) {
        var result = '';
        if (number[0] === '-') {
            result = number.substr(1);
        }
        else {
            result = "-" + number;
        }
        return result;
    }

    function modulus(inputDividend, inputDivisor) {
        validateDividend(inputDividend);
        var dividend = inputDividend.toString();
        var divisor = inputDivisor.toString();
        validate(dividend);
        validate(divisor);
        var sign = '';
        if (dividend[0] === '-') {
            sign = '-';
            dividend = dividend.substr(1);
        }
        if (divisor[0] === '-') {
            divisor = divisor.substr(1);
        }
        var result = subtract(dividend, multiply(divisor, roundOff(divide(dividend, divisor), 0, 2 /* FLOOR */)));
        return sign + result;
    }
    function validate(operand) {
        if (operand.indexOf('.') !== -1) {
            throw new Error('Modulus of non-integers not supported');
        }
    }
    function validateDividend(dividend) {
        if (dividend === 0 || dividend === '0') {
            throw new Error('Cannot divide by 0');
        }
    }

    var BigDecimal = /** @class */ (function () {
        function BigDecimal(num) {
            if (num === void 0) { num = '0'; }
            this.value = BigDecimal.validate(num);
        }
        BigDecimal.negate = function (inputNum) {
            var num = BigDecimal.validate(inputNum);
            return negate(num);
        };
        BigDecimal.ceil = function (inputNum) {
            var num = BigDecimal.validate(inputNum);
            if (num.indexOf('.') === -1) {
                return num;
            }
            return BigDecimal.round(num, 0, 0 /* CEILING */);
        };
        BigDecimal.add = function (inputA, inputB) {
            var a = BigDecimal.validate(inputA);
            var b = BigDecimal.validate(inputB);
            return add(a, b);
        };
        BigDecimal.subtract = function (inputA, inputB) {
            var a = BigDecimal.validate(inputA);
            var b = BigDecimal.validate(inputB);
            return subtract(a, b);
        };
        BigDecimal.multiply = function (inputA, inputB) {
            var a = BigDecimal.validate(inputA);
            var b = BigDecimal.validate(inputB);
            return multiply(a, b);
        };
        BigDecimal.divide = function (inputA, inputB, precision) {
            var a = BigDecimal.validate(inputA);
            var b = BigDecimal.validate(inputB);
            return divide(a, b, precision);
        };
        BigDecimal.modulus = function (inputA, inputB) {
            var a = BigDecimal.validate(inputA);
            var b = BigDecimal.validate(inputB);
            return modulus(a, b);
        };
        BigDecimal.compareTo = function (inputA, inputB) {
            var a = BigDecimal.validate(inputA);
            var b = BigDecimal.validate(inputB);
            return compareTo(a, b);
        };
        BigDecimal.round = function (inputA, precision, mode /* HALF_EVEN */) {
            if (precision === void 0) { precision = 0; }
            if (mode === void 0) { mode = 4; }
            var a = BigDecimal.validate(inputA);
            if (isNaN(precision)) {
                throw Error("Precision is not a num: " + precision);
            }
            return roundOff(a, precision, mode);
        };
        BigDecimal.floor = function (inputA) {
            var a = BigDecimal.validate(inputA);
            if (a.indexOf('.') === -1) {
                return a;
            }
            return BigDecimal.round(a, 0, 2 /* FLOOR */);
        };
        BigDecimal.getPrettyValue = function (inputNum, digits, separator) {
            var num = inputNum;
            var prettyParams = validatePrettyParams({ digits: digits, separator: separator });
            num = BigDecimal.validate(num);
            var neg = num.charAt(0) === '-';
            if (neg) {
                num = num.substring(1);
            }
            var len = num.indexOf('.');
            len = len > 0 ? len : num.length;
            var temp = getTemp(prettyParams, len, num);
            return (neg ? '-' : '') + temp + num.substring(len);
        };
        BigDecimal.validate = function (inputNum) {
            var num = prepareNum(inputNum);
            var isPoint = num.startsWith('.');
            var isDashPoint = num.startsWith('-.');
            if (isPoint) {
                num = "0" + num;
            }
            else if (isDashPoint) {
                num = "-0" + num.substr(1);
            }
            if (/e/i.test(num)) {
                num = getExponentiation(num);
            }
            return num;
        };
        BigDecimal.prototype.getValue = function () {
            return this.value;
        };
        BigDecimal.prototype.getPrettyValue = function (digits, separator) {
            return BigDecimal.getPrettyValue(this.value, digits, separator);
        };
        BigDecimal.prototype.round = function (precision, mode /* HALF_EVEN */) {
            if (precision === void 0) { precision = 0; }
            if (mode === void 0) { mode = 4; }
            if (isNaN(precision)) {
                throw Error("Precision is not a num: " + precision);
            }
            return new BigDecimal(roundOff(this.value, precision, mode));
        };
        BigDecimal.prototype.floor = function () {
            if (this.value.indexOf('.') === -1) {
                return new BigDecimal(this.value);
            }
            return new BigDecimal(this.value).round(0, 2 /* FLOOR */);
        };
        BigDecimal.prototype.ceil = function () {
            if (this.value.indexOf('.') === -1) {
                return new BigDecimal(this.value);
            }
            return new BigDecimal(this.value).round(0, 0 /* CEILING */);
        };
        BigDecimal.prototype.add = function (num) {
            return new BigDecimal(add(this.value, num.getValue()));
        };
        BigDecimal.prototype.subtract = function (num) {
            return new BigDecimal(subtract(this.value, num.getValue()));
        };
        BigDecimal.prototype.multiply = function (num) {
            return new BigDecimal(multiply(this.value, num.getValue()));
        };
        BigDecimal.prototype.divide = function (num, precision) {
            return new BigDecimal(divide(this.value, num.getValue(), precision));
        };
        BigDecimal.prototype.modulus = function (num) {
            return new BigDecimal(modulus(this.value, num.getValue()));
        };
        BigDecimal.prototype.compareTo = function (num) {
            return compareTo(this.value, num.getValue());
        };
        BigDecimal.prototype.negate = function () {
            return new BigDecimal(negate(this.value));
        };
        return BigDecimal;
    }());
    function validatePrettyParams(params) {
        var result = Object.assign({}, params);
        if (utils.checkEveryValueIsEmpty(params.digits, params.separator)) {
            result.digits = DEFAULT_DIGITS;
            result.separator = ',';
        }
        else if (utils.checkSomeValueIsEmpty(params.digits, params.separator)) {
            throw Error('Illegal Arguments. Should pass both digits and separator or pass none');
        }
        return result;
    }
    function getTemp(params, len, num) {
        var temp = '';
        for (var i = len; i > 0;) {
            if (i < params.digits) {
                params.digits = i;
                i = 0;
            }
            else {
                i -= params.digits;
            }
            temp = num.substring(i, i + params.digits) + (i < len - params.digits && i >= 0 ? params.separator : '') + temp;
        }
        return temp;
    }
    function getExponentiation(inputNum) {
        var _a, _b;
        var numParts = inputNum.split(/[eE]/);
        if (numParts.length !== EXPONENTIAL_PARTS_LENGTH) {
            return inputNum;
        }
        var mantisa = trim((_a = numParts[0]) !== null && _a !== void 0 ? _a : '');
        var exponent = (_b = numParts[1]) !== null && _b !== void 0 ? _b : '';
        var offset = 0;
        if (mantisa.indexOf('.') >= 0) {
            exponent = parseInt(exponent) + mantisa.indexOf('.');
            mantisa = mantisa.replace('.', '');
            offset = 1;
        }
        return prepareExponentiation(mantisa, exponent, offset);
    }
    function prepareExponentiation(mantisa, exponent, offset) {
        var num = '';
        if (mantisa.length < exponent) {
            num = mantisa + new Array(exponent - mantisa.length + 1).join('0');
        }
        else if (mantisa.length >= exponent && exponent > 0) {
            num =
                trim(mantisa.substring(0, exponent)) + (mantisa.length > exponent ? "." + mantisa.substring(exponent) : '');
        }
        else {
            num = "0." + new Array(-exponent + offset).join('0') + mantisa;
        }
        return num;
    }
    function prepareNum(inputNum) {
        var num = inputNum;
        if (utils.checkValueIsFilled(inputNum)) {
            num = inputNum.toString();
            if (isNaN(num)) {
                throw Error("Parameter is not a num: " + num);
            }
            if (num[0] === '+') {
                num = num.substring(1);
            }
        }
        else {
            num = '0';
        }
        return num;
    }

    /**
     * Generated bundle index. Do not edit.
     */

    exports.BigDecimal = BigDecimal;

    Object.defineProperty(exports, '__esModule', { value: true });

})));
//# sourceMappingURL=angular-ru-cdk-big-decimal.umd.js.map
