Uploaded image for project: 'Commons Numbers'
  1. Commons Numbers
  2. NUMBERS-147

Fraction/BigFraction from(double, int) should support Integer.MIN_VALUE as max denominator

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.0-beta1
    • 1.0-beta1
    • fraction
    • None

    Description

      Fraction allows the use of Integer.MIN_VALUE for the denominator. The conversion from a double using a maximum denominator only supports values up to Integer.MAX_VALUE. This is a legacy from when Fraction was limited to Integer.MAX_VALUE in the denominator.

      Currently this test fails:

          @Test
          public void testFromDoubleUsingMaxDenominator() {
              Fraction f1 = Fraction.of(-1, Integer.MIN_VALUE);
              Fraction f2 = Fraction.from(f1.doubleValue(), Integer.MIN_VALUE);
              Assertions.assertEquals(f1, f2);
          }
      

      It should be possible to round-trip the most extreme small value that can be stored in a fraction to a double and then back again.

      The method requires updating to set the overflow limit (which is a long) as 2^31 and not 2^31-1.

      The same method is used in BigFraction.from which should also be updated.

      Attachments

        Issue Links

          Activity

            People

              aherbert Alex Herbert
              aherbert Alex Herbert
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h