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

StatUtils.sum returns NaN for zero-length arrays

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1
    • 3.0
    • None
    • None

    Description

      StatUtils.sum returns NaN for zero-length arrays, which is:

      1. inconsistent with the mathematical notion of sum: in maths, sum_

      {i=0}^{N-1} a_i will be 0 for N=0. In particular, the identity

      sum_{i=0}

      ^

      {k-1}

      a_i + sum_

      {i=k}

      ^

      {N-1} = sum_{i=0}^{N-1}

      is broken for k = 0, since NaN + x = NaN, not x.

      2. introduces hard to debug erros (returning a NaN is one of the worst forms of reporting an exceptional condition, as NaNs propagate silently and require manual tracing during the debugging)

      3. enforces "special case" handling when the user expects that the summed array can have a zero length.

      The correct behaviour is, in my opinion, to return 0.0, not NaN in the above case.

      Attachments

        Activity

          People

            Unassigned Unassigned
            rwerp Roman Werpachowski
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: