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 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@201810 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e34b56db3f
commit
d062702366
|
@ -530,13 +530,15 @@ public final class MathUtils {
|
|||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -463,6 +463,13 @@ public final class MathUtilsTest extends TestCase {
|
|||
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() {
|
||||
|
|
|
@ -39,10 +39,14 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
<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.
|
||||
</action>
|
||||
|
|
Loading…
Reference in New Issue