fixed overflow error in gdc computation
JIRA: MATH-238 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@735178 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4564adbf19
commit
dabf3a5beb
|
@ -409,7 +409,7 @@ public final class MathUtils {
|
|||
* @since 1.1
|
||||
*/
|
||||
public static int gcd(int u, int v) {
|
||||
if (u * v == 0) {
|
||||
if ((u == 0) || (v == 0)) {
|
||||
return (Math.abs(u) + Math.abs(v));
|
||||
}
|
||||
// keep u and v negative, as negative integers range down to
|
||||
|
|
|
@ -39,6 +39,9 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
</properties>
|
||||
<body>
|
||||
<release version="2.0" date="TBD" description="TBD">
|
||||
<action dev="luc" type="fix" issue="MATH-238" due-to="Chritian Semrau">
|
||||
Fixed an error in gcd computation for large values.
|
||||
</action>
|
||||
<action dev="luc" type="add" >
|
||||
Added method to walk matrix entries with or without changing them in the
|
||||
visitor design pattern sense. Three different orders can be used, row by row,
|
||||
|
|
|
@ -291,6 +291,9 @@ public final class MathUtilsTest extends TestCase {
|
|||
assertEquals(1, MathUtils.gcd(-a, c));
|
||||
assertEquals(1, MathUtils.gcd(a, -c));
|
||||
assertEquals(1, MathUtils.gcd(-a, -c));
|
||||
|
||||
assertEquals(3 * (1<<15), MathUtils.gcd(3 * (1<<20), 9 * (1<<15)));
|
||||
|
||||
}
|
||||
|
||||
public void testHash() {
|
||||
|
|
Loading…
Reference in New Issue