Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-3

[math] Corrections to Constructor Fraction(double)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • None
    • None
    • Operating System: other
      Platform: All

    • 35434

    Description

      The constructor for Fraction fails for doubles which are almost integer.

      examples should be inserted in th etest case:

      public void testConstructorDouble() {
      try

      { ..... assertFraction(0, 1, new Fraction(0.00000000000001)); assertFraction(2, 5, new Fraction(0.40000000000001)); assertFraction(15, 1, new Fraction(15.0000000000001)); }

      catch (ConvergenceException ex)

      { fail(ex.getMessage()); }

      }

      The fix for this problem is to include the following code in the constructor:

      int n = 0;
      boolean stop = false;

      // check for (almost) integer arguments, which should not go
      // to iterations.
      if (Math.abs(a0 - value)<epsilon)

      { this.numerator = a0; this.denominator = 1; return; }

      do {
      ++n;

      Attachments

        Activity

          People

            Unassigned Unassigned
            j.weimar@tu-bs.de Jörg Weimar
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: