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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Labels:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: