From 86664455a80924f10d537fc2ed4707d6231aa000 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 26 May 2022 22:47:07 +0000 Subject: [PATCH] add VARPA and STDEVPA functions git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1901300 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/ss/formula/eval/FunctionEval.java | 4 +-- .../formula/functions/AggregateFunction.java | 30 ++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java b/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java index 741a7921d0..eb322007fd 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java @@ -336,8 +336,8 @@ public final class FunctionEval { retval[361] = AggregateFunction.AVERAGEA; retval[362] = MinaMaxa.MAXA; retval[363] = MinaMaxa.MINA; - // 364: STDEVPA - // 365: VARPA + retval[364] = AggregateFunction.STDEVPA; + retval[365] = AggregateFunction.VARPA; retval[366] = AggregateFunction.STDEVA; retval[367] = AggregateFunction.VARA; diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/AggregateFunction.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/AggregateFunction.java index 02dd83c93e..b8379bc5ea 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/AggregateFunction.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/AggregateFunction.java @@ -265,6 +265,20 @@ public abstract class AggregateFunction extends MultiOperandNumericFunction { return StatsLib.stdev(values); } }; + public static final Function STDEVPA = new AggregateFunction() { + @Override + protected boolean handleLogicalValues() { + return true; + } + + @Override + protected double evaluate(double[] values) throws EvaluationException { + if (values.length < 1) { + throw new EvaluationException(ErrorEval.DIV_ZERO); + } + return StatsLib.stdevp(values); + } + }; public static final Function SUM = new AggregateFunction() { protected double evaluate(double[] values) { return MathX.sum(values); @@ -296,7 +310,7 @@ public abstract class AggregateFunction extends MultiOperandNumericFunction { protected boolean handleLogicalValues() { return true; } - + @Override protected double evaluate(double[] values) throws EvaluationException { if (values.length < 1) { @@ -305,6 +319,20 @@ public abstract class AggregateFunction extends MultiOperandNumericFunction { return StatsLib.var(values); } }; + public static final Function VARPA = new AggregateFunction() { + @Override + protected boolean handleLogicalValues() { + return true; + } + + @Override + protected double evaluate(double[] values) throws EvaluationException { + if (values.length < 1) { + throw new EvaluationException(ErrorEval.DIV_ZERO); + } + return StatsLib.varp(values); + } + }; public static final Function GEOMEAN = new Geomean(); private static class Product extends AggregateFunction { -- 2.39.5