Replace impl of NormalDistribution.density by calling FastMath.exp(logDensity()) which should be faster.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1534363 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2013-10-21 20:28:05 +00:00
parent 243e7260b9
commit 456723dd14
1 changed files with 1 additions and 5 deletions

View File

@ -41,8 +41,6 @@ public class NormalDistribution extends AbstractRealDistribution {
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
/** Serializable version identifier. */
private static final long serialVersionUID = 8589540077390120676L;
/** √(2 π) */
private static final double SQRT2PI = FastMath.sqrt(2 * FastMath.PI);
/** √(2) */
private static final double SQRT2 = FastMath.sqrt(2.0);
/** Mean of this distribution. */
@ -150,9 +148,7 @@ public class NormalDistribution extends AbstractRealDistribution {
/** {@inheritDoc} */
public double density(double x) {
final double x0 = x - mean;
final double x1 = x0 / standardDeviation;
return FastMath.exp(-0.5 * x1 * x1) / (standardDeviation * SQRT2PI);
return FastMath.exp(logDensity(x));
}
/** {@inheritDoc} */