From 4095d7a02953d7c5def223b2787c972268ba82a4 Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Sat, 11 Apr 2009 15:30:02 +0000 Subject: [PATCH] Restored some double casts to improve ensure correctness does not depend on order of operations or literal conversion, dropped uneccesary parens. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@764208 13f79535-47bb-0310-9956-ffa450edef68 --- .../math/stat/regression/SimpleRegression.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java b/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java index d0037b117..aea4a0cd2 100644 --- a/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java +++ b/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java @@ -124,9 +124,9 @@ public class SimpleRegression implements Serializable { } else { double dx = x - xbar; double dy = y - ybar; - sumXX += dx * dx * n / (n + 1.0); - sumYY += dy * dy * n / (n + 1.0); - sumXY += dx * dy * n / (n + 1.0); + sumXX += dx * dx * (double) n / (n + 1d); + sumYY += dy * dy * (double) n / (n + 1d); + sumXY += dx * dy * (double) n / (n + 1d); xbar += dx / (n + 1.0); ybar += dy / (n + 1.0); } @@ -157,9 +157,9 @@ public class SimpleRegression implements Serializable { if (n > 0) { double dx = x - xbar; double dy = y - ybar; - sumXX -= dx * dx * n / (n - 1.0); - sumYY -= dy * dy * n / (n - 1.0); - sumXY -= dx * dy * n / (n - 1.0); + sumXX -= dx * dx * (double) n / (n - 1d); + sumYY -= dy * dy * (double) n / (n - 1d); + sumXY -= dx * dy * (double) n / (n - 1d); xbar -= dx / (n - 1.0); ybar -= dy / (n - 1.0); sumX -= x; @@ -468,7 +468,7 @@ public class SimpleRegression implements Serializable { */ public double getInterceptStdErr() { return Math.sqrt( - getMeanSquareError() * ((1d / n) + (xbar * xbar) / sumXX)); + getMeanSquareError() * ((1d / (double) n) + (xbar * xbar) / sumXX)); } /** @@ -589,7 +589,7 @@ public class SimpleRegression implements Serializable { * @return the intercept of the regression line */ private double getIntercept(double slope) { - return (sumY - slope * sumX) / (n); + return (sumY - slope * sumX) / n; } /**