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

Fraction.comparTo returns 0 for some differente fractions

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.2
    • Fix Version/s: 2.0
    • Labels:
      None

      Description

      If two different fractions evaluate to the same double due to limited precision,
      the compareTo methode returns 0 as if they were identical.

      // value is roughly PI - 3.07e-18
      Fraction pi1 = new Fraction(1068966896, 340262731);
      
      // value is roughly PI + 1.936e-17
      Fraction pi2 = new Fraction( 411557987, 131002976);
      
      System.out.println(pi1.doubleValue() - pi2.doubleValue()); // exactly 0.0 due to limited IEEE754 precision
      System.out.println(pi1.compareTo(pi2)); // display 0 instead of a negative value
      

        Attachments

          Activity

            People

            • Assignee:
              luc Luc Maisonobe
              Reporter:
              luc Luc Maisonobe
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: