commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1533260 - in /commons/proper/math/trunk/src: changes/changes.xml main/java/org/apache/commons/math3/fraction/BigFraction.java test/java/org/apache/commons/math3/fraction/BigFractionTest.java
Date Thu, 17 Oct 2013 21:12:28 GMT
Author: tn
Date: Thu Oct 17 21:12:28 2013
New Revision: 1533260

URL: http://svn.apache.org/r1533260
Log:
[MATH-1029] Make overflow check symmetric for positive/negative values.

Modified:
    commons/proper/math/trunk/src/changes/changes.xml
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/BigFraction.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/BigFractionTest.java

Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1533260&r1=1533259&r2=1533260&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Thu Oct 17 21:12:28 2013
@@ -51,6 +51,11 @@ If the output is not quite correct, chec
   </properties>
   <body>
     <release version="x.y" date="TBD" description="TBD">
+      <action dev="tn" type="fix" issue="MATH-1029">
+        The "BigFraction" constructor will throw a "FractionConversionException"
+        also in case negative values are provided which exceed the allowed range
+        (+/- Integer.MAX_VALUE).
+      </action>
       <action dev="erans" type="add" issue="MATH-1041" due-to="Sean Owen">
         "Pair": added factory method and "toString" method.
       </action>

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/BigFraction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/BigFraction.java?rev=1533260&r1=1533259&r2=1533260&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/BigFraction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/BigFraction.java
Thu Oct 17 21:12:28 2013
@@ -272,7 +272,8 @@ public class BigFraction
         long overflow = Integer.MAX_VALUE;
         double r0 = value;
         long a0 = (long) FastMath.floor(r0);
-        if (a0 > overflow) {
+
+        if (FastMath.abs(a0) > overflow) {
             throw new FractionConversionException(value, a0, 1l);
         }
 

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/BigFractionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/BigFractionTest.java?rev=1533260&r1=1533259&r2=1533260&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/BigFractionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/BigFractionTest.java
Thu Oct 17 21:12:28 2013
@@ -156,7 +156,19 @@ public class BigFractionTest {
         assertFraction(769, 1250, new BigFraction(0.6152, 9999));
         
         // MATH-996
-        assertFraction(1, 2, new BigFraction(0.5000000001, 10));
+        assertFraction(1, 2, new BigFraction(0.5000000001, 10));        
+    }
+
+    // MATH-1029
+    @Test(expected=FractionConversionException.class)
+    public void testPositiveValueOverflow() {
+        assertFraction((long) 1e10, 1, new BigFraction(1e10, 1000));
+    }
+
+    // MATH-1029
+    @Test(expected=FractionConversionException.class)
+    public void testNegativeValueOverflow() {
+        assertFraction((long) -1e10, 1, new BigFraction(-1e10, 1000));
     }
 
     @Test



Mime
View raw message