You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gilles (JIRA)" <ji...@apache.org> on 2013/08/10 02:59:48 UTC
[jira] [Commented] (MATH-1021) HypergeometricDistribution.sample
suffers from integer overflow
[ https://issues.apache.org/jira/browse/MATH-1021?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13735631#comment-13735631 ]
Gilles commented on MATH-1021:
------------------------------
Thanks for the report and suggested fix.
Committed in revision 1512546.
> HypergeometricDistribution.sample suffers from integer overflow
> ---------------------------------------------------------------
>
> Key: MATH-1021
> URL: https://issues.apache.org/jira/browse/MATH-1021
> Project: Commons Math
> Issue Type: Bug
> Reporter: Brian Bloniarz
>
> Hi, I have an application which broke when ported from commons math 2.2 to 3.2. It looks like the HypergeometricDistribution.sample() method doesn't work as well as it used to with large integer values -- the example code below should return a sample between 0 and 50, but usually returns -50.
> {code}
> import org.apache.commons.math3.distribution.HypergeometricDistribution;
> public class Foo {
> public static void main(String[] args) {
> HypergeometricDistribution a = new HypergeometricDistribution(
> 43130568, 42976365, 50);
> System.out.printf("%d %d%n", a.getSupportLowerBound(), a.getSupportUpperBound()); // Prints "0 50"
> System.out.printf("%d%n",a.sample()); // Prints "-50"
> }
> }
> {code}
> In the debugger, I traced it as far as an integer overflow in HypergeometricDistribution.getNumericalMean() -- instead of doing
> {code}
> return (double) (getSampleSize() * getNumberOfSuccesses()) / (double) getPopulationSize();
> {code}
> it could do:
> {code}
> return getSampleSize() * ((double) getNumberOfSuccesses() / (double) getPopulationSize());
> {code}
> This seemed to fix it, based on a quick test.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira