diff --git a/pmd/regress/test/net/sourceforge/pmd/stat/StatisticalRuleTest.java b/pmd/regress/test/net/sourceforge/pmd/stat/StatisticalRuleTest.java index 9152762a1a..5ce13266b2 100644 --- a/pmd/regress/test/net/sourceforge/pmd/stat/StatisticalRuleTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/stat/StatisticalRuleTest.java @@ -66,7 +66,7 @@ public class StatisticalRuleTest extends TestCase { public static final double MEAN = 49.5; - public static final double SIGMA = 28.86750; + public static final double SIGMA = 29.0115; public static final int NUM_TESTS = 1; public static final double DELTA = 0.005; diff --git a/pmd/src/net/sourceforge/pmd/stat/StatisticalRule.java b/pmd/src/net/sourceforge/pmd/stat/StatisticalRule.java index 10849686b0..f8ada543ee 100644 --- a/pmd/src/net/sourceforge/pmd/stat/StatisticalRule.java +++ b/pmd/src/net/sourceforge/pmd/stat/StatisticalRule.java @@ -77,7 +77,20 @@ public abstract class StatisticalRule extends AbstractRule { } protected double getStdDev() { - return Math.sqrt(((totalSquared / count) - (getMean() * getMean()))); + Iterator points = dataPoints.iterator(); + double mean = getMean(); + double deltaSq = 0.0; + + if (dataPoints.size() < 2) { + return Double.NaN; + } + + while (points.hasNext()) { + DataPoint point = (DataPoint) points.next(); + deltaSq += ((point.getScore() - mean) * (point.getScore() - mean)); + } + + return Math.sqrt( deltaSq / (dataPoints.size() - 1)); } protected SortedSet applyMinimumValue(SortedSet pointSet, double minValue) {