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

MathUtils.factorial(n) fails for n >= 17

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0
    • 2.0
    • None
    • None

    Description

      The result of MathUtils.factorial( n ) for n = 17, 18, 19 is wrong, probably because of rounding errors in the double calculations.

      Replace the first line of MathUtilsTest.testFactorial() by

      for (int i = 1; i <= 20; i++) {

      to check all valid arguments for the long result and see the failure.

      I suggest implementing a simple loop to multiply the long result - or even using a precomputed long[] - instead of adding logarithms.

      Attachments

        Activity

          People

            psteitz Phil Steitz
            chsemrau Christian Semrau
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: