Author: luc
Date: Fri Jan 16 15:06:32 2009
New Revision: 735178
URL: http://svn.apache.org/viewvc?rev=735178&view=rev
Log:
fixed overflow error in gdc computation
JIRA: MATH-238
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
commons/proper/math/trunk/src/site/xdoc/changes.xml
commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java?rev=735178&r1=735177&r2=735178&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
Fri Jan 16 15:06:32 2009
@@ -409,7 +409,7 @@
* @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
Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=735178&r1=735177&r2=735178&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Fri Jan 16 15:06:32 2009
@@ -39,6 +39,9 @@
</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,
Modified:
commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java?rev=735178&r1=735177&r2=735178&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
(original)
+++
commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
Fri Jan 16 15:06:32 2009
@@ -291,6 +291,9 @@
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() {