Details

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

      Windows 7, IntelliJ IDEA 10.5.4.

      Description

      package org.apache.commons.math3.util
      example of usage of round functions of Precision class:

      Precision.round(0.0f, 2, BigDecimal.ROUND_UP) = 0.01
      Precision.round((float)0.0, 2, BigDecimal.ROUND_UP) = 0.01
      Precision.round((float) 0.0, 2) = 0.0
      Precision.round(0.0, 2, BigDecimal.ROUND_UP) = 0.0

      Seems the reason is usage of extending float to double inside round functions and getting influence of memory trash as value.

      I think, same problem will be found at usage of other round modes.

        Activity

        Hide
        Thomas Neidhart added a comment -

        Fixed in r1547649.

        According to BigDecimal.ROUND_UP, the value shall only be rounded up if the discarded fraction is non-zero.

        Show
        Thomas Neidhart added a comment - Fixed in r1547649. According to BigDecimal.ROUND_UP, the value shall only be rounded up if the discarded fraction is non-zero.
        Hide
        Oleksandr Muliarevych added a comment -

        Still left problem with round of zero value for float usage:
        Precision.round(-0.0d, 0) = 0.0
        Precision.round(-0.0f, 0) = -0.0

        Show
        Oleksandr Muliarevych added a comment - Still left problem with round of zero value for float usage: Precision.round(-0.0d, 0) = 0.0 Precision.round(-0.0f, 0) = -0.0
        Hide
        Thomas Neidhart added a comment -

        Could you please create a different issue for this problem.

        Calling Precision.round(x, y) will use the rounding mode ROUND_HALF_UP thus is it different to the problem reported before.

        Show
        Thomas Neidhart added a comment - Could you please create a different issue for this problem. Calling Precision.round(x, y) will use the rounding mode ROUND_HALF_UP thus is it different to the problem reported before.
        Hide
        Thomas Neidhart added a comment -

        The problem you outline is quite interesting. In the case of Precision.round(double, scale), the double value gets internally converted to a BigDecimal, but BigDecimal loses the sign if the value is 0. This is even documented in the javadoc: http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#BigDecimal%28java.lang.String%29

        Show
        Thomas Neidhart added a comment - The problem you outline is quite interesting. In the case of Precision.round(double, scale), the double value gets internally converted to a BigDecimal, but BigDecimal loses the sign if the value is 0. This is even documented in the javadoc: http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#BigDecimal%28java.lang.String%29
        Hide
        Thomas Neidhart added a comment -

        Created issue MATH-1089 for the problem with negative zero, which has already been fixed.

        Show
        Thomas Neidhart added a comment - Created issue MATH-1089 for the problem with negative zero, which has already been fixed.
        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:
            Oleksandr Muliarevych
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development