Author: psteitz
Date: Sat Jun 25 18:19:16 2005
New Revision: 201810

URL: http://svn.apache.org/viewcvs?rev=201810&view=rev
Log:
Changed lcm to throw ArithmeticException (instead of returning bogus
value) if the result is too large to store as an integer.
PR # 35431
Submitted by: Jörg Weimar

Modified:
    
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
    
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
    jakarta/commons/proper/math/trunk/xdocs/changes.xml

Modified: 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java?rev=201810&r1=201809&r2=201810&view=diff
==============================================================================
--- 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
 (original)
+++ 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
 Sat Jun 25 18:19:16 2005
@@ -530,13 +530,15 @@
 
     /**
      * Returns the least common multiple between two integer values.
+     * 
      * @param a the first integer value.
      * @param b the second integer value.
      * @return the least common multiple between a and b.
+     * @throws ArithmeticException if the lcm is too large to store as an int
      * @since 1.1
      */
     public static int lcm(int a, int b) {
-        return Math.abs(a / gcd(a, b) * b);
+        return Math.abs(mulAndCheck(a / gcd(a, b) , b));
     }
 
     /**

Modified: 
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java?rev=201810&r1=201809&r2=201810&view=diff
==============================================================================
--- 
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
 (original)
+++ 
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
 Sat Jun 25 18:19:16 2005
@@ -463,6 +463,13 @@
         assertEquals(150, MathUtils.lcm(-a, b));
         assertEquals(150, MathUtils.lcm(a, -b));
         assertEquals(2310, MathUtils.lcm(a, c));
+        
+        try {
+            MathUtils.lcm(Integer.MAX_VALUE, Integer.MAX_VALUE - 1);
+            fail("Expecting ArithmeticException");
+        } catch (ArithmeticException ex) {
+            // expected
+        }
     }
     
     public void testRoundFloat() {

Modified: jakarta/commons/proper/math/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/math/trunk/xdocs/changes.xml?rev=201810&r1=201809&r2=201810&view=diff
==============================================================================
--- jakarta/commons/proper/math/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/math/trunk/xdocs/changes.xml Sat Jun 25 18:19:16 2005
@@ -39,9 +39,13 @@
   <body>
     <release version="1.1" date="In Development"  
        description="Jakarta Commons Math 1.1 - Development">
-      <action dev="psteitz" type="update" issue="32663"  due-to="Mary Ellen 
Foster">
+      <action dev="psteitz" type="fix" issue="32663"  due-to="Mary Ellen 
Foster">
         Added factories for TTest, ChiSquareTest and TestUtils class with
         static methods to create instances and execute tests.
+      </action>
+      <action dev="psteitz" type="update" issue="35431"  due-to="Jörg Weimar">
+        Changed lcm to throw ArithmeticException (instead of returning bogus
+        value) if the result is too large to store as an integer.
       </action>
       <action dev="psteitz" type="update" issue="35042"  due-to="Paul Field">
         Eliminated repeated endpoint function evalutations in BrentSolver, 
SecantSolver.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to