Harmony
  1. Harmony
  2. HARMONY-6406

Combination of multiply and compareTo BigDecimal methods returns unexpected result

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 5.0M12
    • Fix Version/s: 5.0M16
    • Component/s: Classlib
    • Labels:
      None

      Description

      The following test fails:

      BigDecimal testInstance = BigDecimal.TEN.multiply(new BigDecimal("0.1"));
      int result = testInstance.compareTo(new BigDecimal("1.00"));
      assertEquals(0, result);

      I expect 'result' to be 0, but am obtaining -1.

        Activity

        Richard Zschech created issue -
        Hide
        Richard Zschech added a comment -

        I've found the issue in the aproxPrecision method:

        private int aproxPrecision()

        { return ((precision > 0) ? precision : (int)((this.bitLength - 1) * LOG10_2) + 1); }

        The "+ 1" should only be applied to the computed approximation not to the previously computed precision by moving the first bracket on line 2 to line 4:

        private int aproxPrecision()

        { return (precision > 0) ? precision : ((int)((this.bitLength - 1) * LOG10_2) + 1) ; }
        Show
        Richard Zschech added a comment - I've found the issue in the aproxPrecision method: private int aproxPrecision() { return ((precision > 0) ? precision : (int)((this.bitLength - 1) * LOG10_2) + 1); } The "+ 1" should only be applied to the computed approximation not to the previously computed precision by moving the first bracket on line 2 to line 4: private int aproxPrecision() { return (precision > 0) ? precision : ((int)((this.bitLength - 1) * LOG10_2) + 1) ; }
        Hide
        Tim Ellison added a comment -

        Thanks Richard, and apologies that it took so long to address the problem.

        Patch applied to the MATH module at repo revision r1001723.

        Please check that this fixes the problem for you.

        Show
        Tim Ellison added a comment - Thanks Richard, and apologies that it took so long to address the problem. Patch applied to the MATH module at repo revision r1001723. Please check that this fixes the problem for you.
        Tim Ellison made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Tim Ellison [ tellison ]
        Fix Version/s 5.0M16 [ 12315337 ]
        Resolution Fixed [ 1 ]
        Hide
        Hudson added a comment -

        Integrated in Harmony-1.5-head-linux-x86_64 #971 (See https://hudson.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/971/)
        Apply fix for HARMONY-6406 (Combination of multiply and compareTo BigDecimal methods returns unexpected result)

        Show
        Hudson added a comment - Integrated in Harmony-1.5-head-linux-x86_64 #971 (See https://hudson.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/971/ ) Apply fix for HARMONY-6406 (Combination of multiply and compareTo BigDecimal methods returns unexpected result)
        Hide
        Hudson added a comment -

        Integrated in Harmony-select-1.5-head-linux-x86_64 #125 (See https://hudson.apache.org/hudson/job/Harmony-select-1.5-head-linux-x86_64/125/)
        Apply fix for HARMONY-6406 (Combination of multiply and compareTo BigDecimal methods returns unexpected result)

        Show
        Hudson added a comment - Integrated in Harmony-select-1.5-head-linux-x86_64 #125 (See https://hudson.apache.org/hudson/job/Harmony-select-1.5-head-linux-x86_64/125/ ) Apply fix for HARMONY-6406 (Combination of multiply and compareTo BigDecimal methods returns unexpected result)

          People

          • Assignee:
            Tim Ellison
            Reporter:
            Richard Zschech
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development