javamoney
  1. javamoney
  2. JAVAMONEY-113

Invalid result for remainder, when passig 1L

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1
    • Component/s: Impl: RI
    • Labels:
      None

      Description

      Assuming any amount with a fraction part, applying remainder(1) will result in returning the same amount, which is invalid, it should return the fraction part in such a case:

      MonetaryAmount amnt = ...; // e.g. 1.5
      amnt = amnt.remainder(1);  // returns 1.5, instead of 0.5
      

      Problem is an invalid optimazation:

      public Money remainder(long divisor) {
              if (divisor == 1L) {
                  return this;
              }
              return remainder(BigDecimal.valueOf(divisor));
      }
      

      -> FastMoney may be affected as well (to be verified).

        Activity

        Hide
        atsticks added a comment -

        divideAndRemainder is affected by a similar issues as well, will fix both.

        Show
        atsticks added a comment - divideAndRemainder is affected by a similar issues as well, will fix both.

          People

          • Assignee:
            atsticks
            Reporter:
            atsticks
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: