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

Fraction percentageValue rare overflow

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.0
    • 3.1
    • None

    Description

      The percentageValue() method of the Fraction class works by first multiplying the Fraction by 100, then converting the Fraction to a double. This causes overflows when the numerator is greater than Integer.MAX_VALUE/100, even when the value of the fraction is far below this value.

      The patch changes the method to first convert to a double value, and then multiply this value by 100 - the result should be the same, but with less overflows. An addition to the test for the method that covers this bug is also included.

      Attachments

        1. percentageValueOverflow.patch
          1 kB
          Baste Nesse Buanes

        Activity

          People

            Unassigned Unassigned
            snalin Baste Nesse Buanes
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: