/*
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 { CalcFunctionUtilities } from "./CalcFunctionUtilities";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { runOn, markType } from "igniteui-angular-core";
import { CalcArgumentHelper } from "./CalcArgumentHelper";
import { truncate, intDivide } from "igniteui-angular-core";
/**
 * @hidden
 */
export class UltraCalcFunctionTrimMean extends BuiltInFunctionBase {
    evaluate(a, b) {
        let c = a.pop();
        let d = a.pop();
        if (d.isError) {
            return new ExcelCalcValue(d.toErrorValue());
        }
        if (c.isError) {
            return new ExcelCalcValue(c.toErrorValue());
        }
        let e = c._toDouble3();
        let f = CalcFunctionUtilities.o(10);
        if (e < 0 || e >= 1) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(4));
        }
        try {
            CalcArgumentHelper.c(d, 0, 1229, runOn(f, f.add));
            if (f.count == 0) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(4));
            }
            let g = truncate((e * f.count));
            g -= g % 2;
            if (g > 0) {
                f.y();
            }
            let h = 0;
            for (let i = (intDivide(g, 2)), j = f.count - (intDivide(g, 2)); i < j; i++) {
                h += f._inner[i];
            }
            let k = CalcFunctionUtilities.t(f.count - g, h);
            return new ExcelCalcValue(k);
        }
        finally {
            CalcFunctionUtilities.ac(f);
        }
    }
    get_name() {
        return "trimmean";
    }
    get name() {
        return this.get_name();
    }
    get_minArgs() {
        return 2;
    }
    get minArgs() {
        return this.get_minArgs();
    }
    get_maxArgs() {
        return 2;
    }
    get maxArgs() {
        return this.get_maxArgs();
    }
}
UltraCalcFunctionTrimMean.$t = markType(UltraCalcFunctionTrimMean, 'UltraCalcFunctionTrimMean', BuiltInFunctionBase.$);
//# sourceMappingURL=UltraCalcFunctionTrimMean.js.map