Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4904082

Semantics of divideInteger and remainder methods should be updated and clarified

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      tiger
    • CPU:
      generic
    • OS:
      generic

      Description

      In the draft of jsr13 described in 4851776, the divideInteger and remainder methods are underspecified. The 4851776-era implementation of divideInteger also returns a result with zero scale; in other words, all trailing zeros of the integer results are explicitly stored.

      This has a number of problems:

      1. This result can different from the result of an exact divide even if the exact quotient is an integer. For example, by the exact divide scale rules

      1200e2 / 100 = 12e2

      while (abusing notation)

      1200e2 divideInteger 100 = 1200

      2. The rules can create unnecessary large representations; e.g.

      by the exact divide rules

      1e100 / 1 = 1e100

      while divideInteger would return

      10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

      These problems can be solved by redefining a divideInteger method to use the same preferred scale as the exact divide.

      As for remainder, the 4851776 remainder(BigDecimal, MathContext) JavaDoc does not clearly state that the MathContext's rounding effects apply to the implicit divide which determines the remainder and not to the remainder result itself. The remainder computation should be described in terms of the results of the divideInteger method; e.g.

      a.remainder(b) ==

      a - (a.divideInteger(b)*b)

      This also implicitly defines the preferred scale of the remainder.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              darcy Joe Darcy
              Reporter:
              darcy Joe Darcy
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: