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

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        11h 19m 1 Thomas Neidhart 03/Dec/13 23:51
        Resolved Resolved Reopened Reopened
        36d 12h 4m 1 Oleksandr Muliarevych 09/Jan/14 11:55
        Reopened Reopened Resolved Resolved
        1h 22m 1 Thomas Neidhart 09/Jan/14 13:18
        Resolved Resolved Closed Closed
        130d 1h 54m 1 Luc Maisonobe 19/May/14 16:13
        Luc Maisonobe made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        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.
        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
        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
        Thomas Neidhart made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        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.
        Oleksandr Muliarevych made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        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
        Thomas Neidhart made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 3.3 [ 12324600 ]
        Resolution Fixed [ 1 ]
        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.
        Oleksandr Muliarevych created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Oleksandr Muliarevych
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development