On Tue, Jun 12, 2012 at 8:13 AM, Mikkel Meyer Andersen <m...@mikl.dk> wrote:

> 2012/6/12 Thomas Neidhart <thomas.neidh...@gmail.com>:
> > On 06/08/2012 01:04 PM, m...@apache.org wrote:
> >> Author: mikl
> >> Date: Fri Jun  8 11:04:11 2012
> >> New Revision: 1348024
> >>
> >> URL: http://svn.apache.org/viewvc?rev=1348024&view=rev
> >> Log:
> >> MATH-790: Patch applied to fix the overflow issue.
> >>
> >> Modified:
> >>
> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java
> >>
> commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java
> >>
> >> Modified:
> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java
> >> URL:
> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java?rev=1348024&r1=1348023&r2=1348024&view=diff
> >>
> ==============================================================================
> >> ---
> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java
> (original)
> >> +++
> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java
> Fri Jun  8 11:04:11 2012
> >> @@ -170,11 +170,11 @@ public class MannWhitneyUTest {
> >>                                               final int n2)
> >>          throws ConvergenceException, MaxCountExceededException {
> >>
> >> -        final int n1n2prod = n1 * n2;
> >> +        final double n1n2prod = n1 * n2;
> >>
> >>          //
> http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U#Normal_approximation
> >> -        final double EU = (double) n1n2prod / 2.0;
> >> -        final double VarU = (double) (n1n2prod * (n1 + n2 + 1)) / 12.0;
> >> +        final double EU = n1n2prod / 2.0;
> >> +        final double VarU = n1n2prod * (n1 + n2 + 1) / 12.0;
> >>
> >>          final double z = (Umin - EU) / FastMath.sqrt(VarU);
> >
> > just a small thing, but wouldn't it be better to do a long
> > multiplication and convert the result to double?
> >
> > Thomas
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> > For additional commands, e-mail: dev-h...@commons.apache.org
> >
> Do you mean for n1n2prod? Sorry for my ignorance, but what would that
> help? Wouldn't that require more implicit conversions?
>

I just quickly checked to make sure I had the right understanding, but the
line:

>> +        final double n1n2prod = n1 * n2;

still does a int multiplication and may overflow (if n1 and n2 are too big).

Maybe the overflow problem was not in this line but in this one:

>> +        final double VarU = n1n2prod * (n1 + n2 + 1) / 12.0;

so the problem is hidden right now.

Thomas

Reply via email to