Hi all,
Now that I look at this code again, should we not attempt to avoid divide
by zero in case a == b, in this method, and perhaps other methods of this
class?
Also, looking that the Wikipedia article, at
http://en.wikipedia.org/wiki/Triangular_distribution (which is referenced
in the javadoc of this class), "if (p <= (c - a) / (b - a))" should become
"if (p < (c - a) / (b - a)) " instead. Just to keep it consistent with the
Wikipedia article...?
Best regards,
Dennis
er...@apache.org wrote:
Author: erans
Date: Wed Feb 22 23:04:32 2012
New Revision: 1292572
URL: http://svn.apache.org/viewvc?rev=1292572&view=rev
Log:
MATH-746
Removed strict equality special case.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java?rev=1292572&r1=1292571&r2=1292572&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java
Wed Feb 22 23:04:32 2012
@@ -251,20 +251,16 @@ public class TriangularDistribution exte
@Override
public double inverseCumulativeProbability(double p)
throws OutOfRangeException {
- if (p < 0.0 || p > 1.0) {
+ if (p < 0 || p > 1) {
throw new OutOfRangeException(p, 0, 1);
}
- if (p == 0.0) {
+ if (p == 0) {
return a;
}
- if (p == 1.0) {
+ if (p == 1) {
return b;
}
- final double pc = (c - a) / (b - a);
- if (p == pc) {
- return c;
- }
- if (p < pc) {
+ if (p <= (c - a) / (b - a)) {
return a + FastMath.sqrt(p * (b - a) * (c - a));
}
return b - FastMath.sqrt((1 - p) * (b - a) * (b - c));
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org