/*
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 { BuiltInFunctionBase } from "./BuiltInFunctionBase";
import { ExcelCalcValue } from "./ExcelCalcValue";
import { fromEnum, markType } from "igniteui-angular-core";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
/**
 * @hidden
 */
export let UltraCalcFunctionIRR = /*@__PURE__*/ (() => {
    class UltraCalcFunctionIRR extends BuiltInFunctionBase {
        evaluate(a, b) {
            let c = 1E-07;
            let d = 0.1;
            if (b == 2) {
                let e = a.pop();
                if (!((() => { let f = e._toDouble1(d); d = f.p0; return f.ret; })())) {
                    return new ExcelCalcValue(new ExcelCalcErrorValue(4));
                }
                if (Math.abs(d) < c) {
                    d = 0.1;
                }
            }
            d += 1;
            let f = a.pop();
            if (f._w == false) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(1));
            }
            let g = 0;
            let h = 0;
            let i = 0;
            for (let j = 0; j < 20; ++j) {
                let k = true;
                let l = 0;
                let m = false;
                let n = false;
                let o = f.toArrayProxy();
                for (let p of fromEnum(o)) {
                    if (!((() => { let q = p._toDouble1(i); i = q.p0; return q.ret; })())) {
                        continue;
                    }
                    if (i < 0) {
                        n = true;
                    }
                    else if (0 < i) {
                        m = true;
                    }
                    l++;
                    if (k) {
                        g = i;
                        h = 0;
                        k = false;
                    }
                    else {
                        h = g + (h * d);
                        g = i + (g * d);
                    }
                }
                if (l < 2 || n == false || m == false) {
                    return new ExcelCalcValue(new ExcelCalcErrorValue(4));
                }
                let q = g / h;
                d -= q;
                if (Math.abs(q) < c) {
                    return new ExcelCalcValue(d - 1);
                }
                if (Math.abs(d) < c) {
                    return new ExcelCalcValue(new ExcelCalcErrorValue(4));
                }
            }
            return new ExcelCalcValue(new ExcelCalcErrorValue(4));
        }
        canParameterBeEnumerable(a) {
            return a == 0;
        }
        get_name() {
            return "irr";
        }
        get name() {
            return this.get_name();
        }
        get_minArgs() {
            return 1;
        }
        get minArgs() {
            return this.get_minArgs();
        }
        get_maxArgs() {
            return 2;
        }
        get maxArgs() {
            return this.get_maxArgs();
        }
    }
    UltraCalcFunctionIRR.$t = markType(UltraCalcFunctionIRR, 'UltraCalcFunctionIRR', BuiltInFunctionBase.$);
    return UltraCalcFunctionIRR;
})();
