/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import * as tslib_1 from "tslib";
import { Base, String_$type, markType } from "igniteui-angular-core";
import { ArgumentOutOfRangeException } from "igniteui-angular-core";
import { DivideByZeroException } from "./DivideByZeroException";
import { MathUtilities } from "./MathUtilities";
import { List$1 } from "igniteui-angular-core";
import { log10, logBase, isInfinity, isNaN_ } from "igniteui-angular-core";
import { stringReplace, stringContains, stringEmpty, stringToCharArray, stringCompare } from "igniteui-angular-core";
import { numberToString2 } from "igniteui-angular-core";
import { stringFormat } from "igniteui-angular-core";
/**
 * @hidden
 */
var UltraCalcFunctionComplex_ComplexNumber = /** @class */ (function (_super) {
    tslib_1.__extends(UltraCalcFunctionComplex_ComplexNumber, _super);
    function UltraCalcFunctionComplex_ComplexNumber(a) {
        var _rest = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            _rest[_i - 1] = arguments[_i];
        }
        var _this = _super.call(this) || this;
        _this.ai = 0;
        _this.ae = 0;
        _this.am = null;
        _this.x = false;
        a = (a == void 0) ? 0 : a;
        switch (a) {
            case 0:
                {
                    var c = _rest[0];
                    var d = _rest[1];
                    var e = _rest[2];
                    var f = [c, d, e, true];
                    {
                        var h = f[0];
                        var i = f[1];
                        var j = f[2];
                        var k = f[3];
                        _this.ai = h;
                        _this.ae = i;
                        _this.am = j;
                        _this.x = k;
                    }
                }
                break;
            case 1:
                {
                    var c_1 = _rest[0];
                    var d_1 = _rest[1];
                    _this.x = ((function () { var e = UltraCalcFunctionComplex_ComplexNumber.z(c_1, d_1, _this.ai, _this.ae, _this.am); _this.ai = e.p2; _this.ae = e.p3; _this.am = e.p4; return e.ret; })());
                }
                break;
            case 2:
                {
                    var c = _rest[0];
                    var d = _rest[1];
                    var e = _rest[2];
                    var f = _rest[3];
                    _this.ai = c;
                    _this.ae = d;
                    _this.am = e;
                    _this.x = f;
                }
                break;
        }
        return _this;
    }
    Object.defineProperty(UltraCalcFunctionComplex_ComplexNumber.prototype, "aj", {
        get: function () {
            return this.ai;
        },
        set: function (a) {
            this.ai = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(UltraCalcFunctionComplex_ComplexNumber.prototype, "af", {
        get: function () {
            return this.ae;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(UltraCalcFunctionComplex_ComplexNumber.prototype, "an", {
        get: function () {
            return this.am;
        },
        set: function (a) {
            if (a != "i" && a != "j") {
                throw new ArgumentOutOfRangeException(0);
            }
            this.am = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(UltraCalcFunctionComplex_ComplexNumber.prototype, "y", {
        get: function () {
            if (isInfinity(this.aj) || isNaN_(this.aj)) {
                return false;
            }
            if (isInfinity(this.af) || isNaN_(this.af)) {
                return false;
            }
            return this.x;
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionComplex_ComplexNumber.prototype.toString = function () {
        if (this.y == false) {
            return "#NUM";
        }
        return UltraCalcFunctionComplex_ComplexNumber.al(this.aj, this.af, this.an);
    };
    UltraCalcFunctionComplex_ComplexNumber.prototype.ab = function () {
        return Math.sqrt(Math.pow(this.aj, 2) + Math.pow(this.af, 2));
    };
    UltraCalcFunctionComplex_ComplexNumber.prototype.ac = function () {
        if (this.af == 0 && this.aj == 0) {
            throw new DivideByZeroException(null, null);
        }
        return Math.atan2(this.af, this.aj);
    };
    UltraCalcFunctionComplex_ComplexNumber.prototype.c = function () {
        return new UltraCalcFunctionComplex_ComplexNumber(0, this.ai, -this.ae, this.am);
    };
    UltraCalcFunctionComplex_ComplexNumber.prototype.d = function () {
        var a = Math.cos(this.aj) * Math.cosh(this.af);
        var b = -(Math.sin(this.aj) * Math.sinh(this.af));
        return new UltraCalcFunctionComplex_ComplexNumber(0, a, b, this.an);
    };
    UltraCalcFunctionComplex_ComplexNumber.prototype.e = function () {
        var a = Math.pow(2.7182818284590451, this.aj);
        var b = Math.cos(this.af) * a;
        var c = Math.sin(this.af) * a;
        var d = new UltraCalcFunctionComplex_ComplexNumber(0, b, c, this.an);
        return d;
    };
    UltraCalcFunctionComplex_ComplexNumber.prototype.ad = function () {
        var a = Math.pow(this.aj, 2);
        var b = Math.pow(this.af, 2);
        var c = a + b;
        var d = Math.sqrt(c);
        return d;
    };
    UltraCalcFunctionComplex_ComplexNumber.prototype.m = function () {
        var a = this.ad();
        var b = Math.log(a);
        var c = this.ak();
        var d = new UltraCalcFunctionComplex_ComplexNumber(0, b, c, this.an);
        return d;
    };
    UltraCalcFunctionComplex_ComplexNumber.prototype.n = function () {
        return UltraCalcFunctionComplex_ComplexNumber.k(this.m(), UltraCalcFunctionComplex_ComplexNumber.ag);
    };
    UltraCalcFunctionComplex_ComplexNumber.prototype.o = function () {
        return UltraCalcFunctionComplex_ComplexNumber.k(this.m(), UltraCalcFunctionComplex_ComplexNumber.ah);
    };
    UltraCalcFunctionComplex_ComplexNumber.prototype.u = function (a) {
        var b = this.ad();
        var c = this.ak();
        var d = Math.pow(b, a);
        var e = c * a;
        var f = d * (Math.cos(e));
        var g = d * (Math.sin(e));
        return new UltraCalcFunctionComplex_ComplexNumber(0, f, g, this.an);
    };
    UltraCalcFunctionComplex_ComplexNumber.prototype.v = function () {
        var a = Math.sin(this.aj) * Math.cosh(this.af);
        var b = Math.cos(this.aj) * Math.sinh(this.af);
        return new UltraCalcFunctionComplex_ComplexNumber(0, a, b, this.an);
    };
    UltraCalcFunctionComplex_ComplexNumber.prototype.w = function () {
        var a = this.ad();
        var b = this.ak();
        var c = Math.sqrt(a);
        var d = b / 2;
        var e = c * Math.cos(d);
        var f = c * Math.sin(d);
        return new UltraCalcFunctionComplex_ComplexNumber(0, e, f, this.an);
    };
    UltraCalcFunctionComplex_ComplexNumber.prototype.ak = function () {
        return Math.atan2(this.af, this.aj);
    };
    UltraCalcFunctionComplex_ComplexNumber.z = function (a, b, c, d, e) {
        b = stringReplace(b, " ", "");
        var f = UltraCalcFunctionComplex_ComplexNumber.b(b);
        var g = f.length;
        if (g > 2 || g <= 0) {
            c = 0;
            d = 0;
            e = "i";
            return {
                ret: false,
                p2: c,
                p3: d,
                p4: e
            };
        }
        var h;
        var i;
        var j;
        if (g == 1) {
            i = b;
            j = ((function () { var k = UltraCalcFunctionComplex_ComplexNumber.aa(a, b, d, e); d = k.p2; e = k.p3; return k.ret; })());
            if (j) {
                c = 0;
            }
            else {
                d = 0;
                j = ((function () { var k = MathUtilities.c(b, a, c); c = k.p2; return k.ret; })());
                if (j == false) {
                    return {
                        ret: false,
                        p2: c,
                        p3: d,
                        p4: e
                    };
                }
            }
        }
        else {
            h = f[0];
            i = f[1];
            j = ((function () { var k = MathUtilities.c(h, a, c); c = k.p2; return k.ret; })());
            if (j == false) {
                d = 0;
                e = "i";
                return {
                    ret: false,
                    p2: c,
                    p3: d,
                    p4: e
                };
            }
            j = ((function () { var k = UltraCalcFunctionComplex_ComplexNumber.aa(a, i, d, e); d = k.p2; e = k.p3; return k.ret; })());
            if (j == false) {
                return {
                    ret: false,
                    p2: c,
                    p3: d,
                    p4: e
                };
            }
        }
        return {
            ret: true,
            p2: c,
            p3: d,
            p4: e
        };
    };
    UltraCalcFunctionComplex_ComplexNumber.aa = function (a, b, c, d) {
        d = stringContains(b, "j") ? "j" : "i";
        if (stringContains(b, "i") == false && stringContains(b, "j") == false) {
            c = 0;
            return {
                ret: false,
                p2: c,
                p3: d
            };
        }
        switch (b) {
            case "i":
            case "j":
            case "+i":
            case "+j":
                c = 1;
                return {
                    ret: true,
                    p2: c,
                    p3: d
                };
            case "-i":
            case "-j":
                c = -1;
                return {
                    ret: true,
                    p2: c,
                    p3: d
                };
        }
        b = stringReplace(b, "i", stringEmpty());
        b = stringReplace(b, "j", stringEmpty());
        return {
            ret: ((function () { var e = MathUtilities.c(b, a, c); c = e.p2; return e.ret; })()),
            p2: c,
            p3: d
        };
    };
    UltraCalcFunctionComplex_ComplexNumber.b = function (a) {
        var b = new List$1(String_$type, 2, 1);
        var c = a.substr(0, 1);
        var d = stringToCharArray(a);
        for (var e = 1; e < d.length; e++) {
            var f = d[e];
            if (f == '-' || f == '+') {
                var g = d[e - 1].toString().toLowerCase();
                if (g != "e") {
                    b.add(c);
                    c = stringEmpty();
                }
            }
            c += f;
        }
        b.add(c);
        return b.toArray();
    };
    UltraCalcFunctionComplex_ComplexNumber.al = function (a, b, c) {
        var d = "G";
        a = MathUtilities.i(a);
        b = MathUtilities.i(b);
        var e;
        if (a == 0 && b == 0) {
            e = "0";
        }
        else if (a != 0 && b == 0) {
            e = numberToString2(a, d);
        }
        else {
            var f = (b > 0) ? "+" : "-";
            var g = void 0;
            if (a != 0) {
                g = numberToString2(a, d);
            }
            else {
                g = stringEmpty();
                if (f == "+") {
                    f = stringEmpty();
                }
            }
            b = Math.abs(b);
            var h = stringFormat("{0}{1}", f, (b == 1) ? stringEmpty() : numberToString2(b, d));
            e = stringFormat("{0}{1}{2}", g, h, c);
        }
        return e;
    };
    Object.defineProperty(UltraCalcFunctionComplex_ComplexNumber, "g", {
        get: function () {
            if (UltraCalcFunctionComplex_ComplexNumber.f == null) {
                UltraCalcFunctionComplex_ComplexNumber.f = new UltraCalcFunctionComplex_ComplexNumber(2, 0, 0, "i", false);
            }
            return UltraCalcFunctionComplex_ComplexNumber.f;
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionComplex_ComplexNumber.i = function (a, b) {
        if (stringCompare(b.an, a.an) != 0) {
            return UltraCalcFunctionComplex_ComplexNumber.g;
        }
        var c = Math.pow(b.aj, 2) + Math.pow(b.af, 2);
        var d = ((a.aj * b.aj) + (a.af * b.af)) / c;
        var e = ((a.af * b.aj) - (a.aj * b.af)) / c;
        var f = new UltraCalcFunctionComplex_ComplexNumber(0, d, e, a.an);
        return f;
    };
    UltraCalcFunctionComplex_ComplexNumber.j = function (a, b) {
        if (stringCompare(a.an, b.an) != 0) {
            return UltraCalcFunctionComplex_ComplexNumber.g;
        }
        var c = ((a.aj * b.aj) - (a.af * b.af));
        var d = ((a.aj * b.af) + (a.af * b.aj));
        var e = new UltraCalcFunctionComplex_ComplexNumber(0, c, d, a.an);
        return e;
    };
    UltraCalcFunctionComplex_ComplexNumber.k = function (a, b) {
        var c = a.an;
        var d = a.aj * b;
        var e = a.af * b;
        return new UltraCalcFunctionComplex_ComplexNumber(0, d, e, c);
    };
    UltraCalcFunctionComplex_ComplexNumber.h = function (a, b) {
        if (stringCompare(a.an, b.an) != 0) {
            return UltraCalcFunctionComplex_ComplexNumber.g;
        }
        var c = a.aj + b.aj;
        var d = a.af + b.af;
        var e = new UltraCalcFunctionComplex_ComplexNumber(0, c, d, a.an);
        return e;
    };
    UltraCalcFunctionComplex_ComplexNumber.l = function (a, b) {
        if (stringCompare(a.an, b.an) != 0) {
            return UltraCalcFunctionComplex_ComplexNumber.g;
        }
        var c = a.aj - b.aj;
        var d = a.af - b.af;
        var e = new UltraCalcFunctionComplex_ComplexNumber(0, c, d, a.an);
        return e;
    };
    UltraCalcFunctionComplex_ComplexNumber.$t = markType(UltraCalcFunctionComplex_ComplexNumber, 'UltraCalcFunctionComplex_ComplexNumber');
    UltraCalcFunctionComplex_ComplexNumber.f = null;
    UltraCalcFunctionComplex_ComplexNumber.a = ['+', '-'];
    UltraCalcFunctionComplex_ComplexNumber.ag = log10(2.7182818284590451);
    UltraCalcFunctionComplex_ComplexNumber.ah = logBase(2.7182818284590451, 2);
    return UltraCalcFunctionComplex_ComplexNumber;
}(Base));
export { UltraCalcFunctionComplex_ComplexNumber };
//# sourceMappingURL=UltraCalcFunctionComplex_ComplexNumber.js.map