This makes it somewhat harder to read the docs code which is where I read docs 90+% of the time.
On the other hand my IDE will do the right thing if I ask it to. Sent from my iPhone On Oct 20, 2013, at 14:27, Thomas Neidhart <thomas.neidh...@gmail.com> wrote: > On 10/20/2013 11:24 PM, t...@apache.org wrote: >> Author: tn >> Date: Sun Oct 20 21:24:45 2013 >> New Revision: 1533990 >> >> URL: http://svn.apache.org/r1533990 >> Log: >> [MATH-1039] Avoid code duplication by calling logDensity itself. >> >> Modified: >> >> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java >> >> Modified: >> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java >> URL: >> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java?rev=1533990&r1=1533989&r2=1533990&view=diff >> ============================================================================== >> --- >> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java >> (original) >> +++ >> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java >> Sun Oct 20 21:24:45 2013 >> @@ -136,24 +136,8 @@ public class BetaDistribution extends Ab >> >> /** {@inheritDoc} */ >> public double density(double x) { >> - recomputeZ(); >> - if (x < 0 || x > 1) { >> - return 0; >> - } else if (x == 0) { >> - if (alpha < 1) { >> - throw new >> NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_0_FOR_SOME_ALPHA, >> alpha, 1, false); >> - } >> - return 0; >> - } else if (x == 1) { >> - if (beta < 1) { >> - throw new >> NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_1_FOR_SOME_BETA, >> beta, 1, false); >> - } >> - return 0; >> - } else { >> - double logX = FastMath.log(x); >> - double log1mX = FastMath.log1p(-x); >> - return FastMath.exp((alpha - 1) * logX + (beta - 1) * log1mX - >> z); >> - } >> + final double logDensity = logDensity(x); >> + return logDensity == Double.NEGATIVE_INFINITY ? 0 : >> FastMath.exp(logDensity); >> } >> >> /** {@inheritDoc} **/ > > I did this change for one class, but I propose to do this whereever > applicable to avoid code duplication in the distribution classes. > > WDYT? > > Thomas > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org