Commons Math
  1. Commons Math
  2. MATH-1089

Precision.round() returns different results when provided negative zero as double or float

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.3
    • Labels:
      None

      Description

      Precision.round(-0.0d, x) = 0.0
      Precision.round(-0.0f, x) = -0.0

      After discussion on the mailinglist, the result should always be -0.0.

        Activity

        Hide
        Thomas Neidhart added a comment -

        This not only affects negative zero, but all negative values that would be rounded to 0.
        In these cases the result should be negative zero to be consistent with the result of Precision.round(float, x).

        Show
        Thomas Neidhart added a comment - This not only affects negative zero, but all negative values that would be rounded to 0. In these cases the result should be negative zero to be consistent with the result of Precision.round(float, x).
        Hide
        Thomas Neidhart added a comment -

        Fixed in r1558933.

        Show
        Thomas Neidhart added a comment - Fixed in r1558933.
        Hide
        Gilles added a comment -

        I propose the attached patch; overall it is probably faster, though the absolute speed difference will be marginal in most cases.

        Show
        Gilles added a comment - I propose the attached patch; overall it is probably faster, though the absolute speed difference will be marginal in most cases.
        Hide
        Thomas Neidhart added a comment -

        Yes, this solution is cleaner, feel free to already commit the patch.

        Show
        Thomas Neidhart added a comment - Yes, this solution is cleaner, feel free to already commit the patch.
        Hide
        Gilles added a comment -

        Committed in revision 1559067.

        Show
        Gilles added a comment - Committed in revision 1559067.
        Hide
        Luc Maisonobe added a comment -

        Closing all resolved issue now available in released 3.3 version.

        Show
        Luc Maisonobe added a comment - Closing all resolved issue now available in released 3.3 version.

          People

          • Assignee:
            Unassigned
            Reporter:
            Thomas Neidhart
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development