commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r617407 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/fraction/Fraction.java test/org/apache/commons/math/fraction/FractionTest.java
Date Fri, 01 Feb 2008 09:39:15 GMT
Author: luc
Date: Fri Feb  1 01:39:14 2008
New Revision: 617407

URL: http://svn.apache.org/viewvc?rev=617407&view=rev
Log:
replaced maxDenominatorDigit by maxDenominator in constructor
it is more straightforward and avoid an exception
JIRA: MATH-181

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/Fraction.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionTest.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/Fraction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/Fraction.java?rev=617407&r1=617406&r2=617407&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/Fraction.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/Fraction.java Fri
Feb  1 01:39:14 2008
@@ -33,20 +33,6 @@
     /** A fraction representing "0 / 1". */
     public static final Fraction ZERO = new Fraction(0, 1);
 
-    /**
-     * The maximal number of denominator digits that can be requested for double to fraction
-     * conversion.
-     * <p>
-     * When <code>d</code> digits are requested, an integer threshold is
-     * initialized with the value 10<sup>d</sup>. Therefore, <code>d</code>
-     * cannot be larger than this constant. Since the java language uses 32 bits
-     * signed integers, the value for this constant is 9.
-     * </p>
-     * 
-     * @see #Fraction(double,int)
-     */
-    public static final int MAX_DENOMINATOR_DIGITS = 9;
-    
     /** Serializable version identifier */
     private static final long serialVersionUID = 5463066929751300926L;
     
@@ -89,22 +75,6 @@
     }
 
     /**
-     * Convert a number of denominator digits to a denominator max value.
-     * @param denominatorDigits The maximum number of denominator digits.
-     * @return the maximal value for denominator
-     * @throws IllegalArgumentException if more than {@link #MAX_DENOMINATOR_DIGITS}
-     *         are requested
-     */
-    private static int maxDenominator(int denominatorDigits)
-        throws IllegalArgumentException
-    {
-        if (denominatorDigits > MAX_DENOMINATOR_DIGITS) {
-            throw new IllegalArgumentException("too many digits requested");
-        }
-        return (int)Math.pow(10, denominatorDigits);
-    }
-
-    /**
      * Create a fraction given the double value and maximum number of
      * denominator digits.
      * <p>
@@ -115,16 +85,14 @@
      * </ul>
      * </p>
      * @param value the double value to convert to a fraction.
-     * @param denominatorDigits The maximum number of denominator digits.
+     * @param maxDenominator The maximum allowed value for denominator
      * @throws FractionConversionException if the continued fraction failed to
      *         converge
-     * @throws IllegalArgumentException if more than {@link #MAX_DENOMINATOR_DIGITS}
-     *         are requested
      */
-    public Fraction(double value, int denominatorDigits)
-        throws FractionConversionException, IllegalArgumentException
+    public Fraction(double value, int maxDenominator)
+        throws FractionConversionException
     {
-       this(value, 0, maxDenominator(denominatorDigits), 100);
+       this(value, 0, maxDenominator, 100);
     }
 
     /**

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionTest.java?rev=617407&r1=617406&r2=617407&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionTest.java
Fri Feb  1 01:39:14 2008
@@ -123,23 +123,14 @@
 
     // MATH-181
     public void testDigitLimitConstructor() throws ConvergenceException  {
-        assertFraction(2, 5, new Fraction(0.4, 1));
-        assertFraction(2, 5, new Fraction(0.4, 2));
-        assertFraction(2, 5, new Fraction(0.4, 3));
+        assertFraction(2, 5, new Fraction(0.4,   9));
+        assertFraction(2, 5, new Fraction(0.4,  99));
+        assertFraction(2, 5, new Fraction(0.4, 999));
 
-        assertFraction(3, 5,      new Fraction(0.6152, 1));
-        assertFraction(8, 13,     new Fraction(0.6152, 2));
-        assertFraction(510, 829,  new Fraction(0.6152, 3));
-        assertFraction(769, 1250, new Fraction(0.6152, 4));
-
-        try {
-            new Fraction(0.6152, 15);
-            fail("an exception should have been thrown");
-        } catch (IllegalArgumentException iae) {
-            // expected behavior
-        } catch (Exception e) {
-            fail("wrong exception caught");
-        }
+        assertFraction(3, 5,      new Fraction(0.6152,    9));
+        assertFraction(8, 13,     new Fraction(0.6152,   99));
+        assertFraction(510, 829,  new Fraction(0.6152,  999));
+        assertFraction(769, 1250, new Fraction(0.6152, 9999));
     }
 
     public void testEpsilonLimitConstructor() throws ConvergenceException  {



Mime
View raw message