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

Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 9
    • Component/s: core-libs
    • Subcomponent:
    • Resolved In Build:
      b120

      Description

      First of all - a big thank you is in order for getting the increment, decrement and negate Exact methods into java.math. This will help us a lot in Nashorn once we get these intrinsifed (even now it helps and gives me performance)

      I also talked to Stephen Coleburne (JSR-310) about our various java.math use cases this weekend.

      It would be great if we could get a couple of more last minute changes into java.math, no biggie if it's too late or anything, but it would further simplify the needs of both Nashorn and JSR-310, the date/time API.

          public static int floorMod(long a, int b) {
              return (int) (((a % b) + b) % b);
          }

      and

          public static int floorDiv(int a, int b) {
              return (a >= 0 ? a / b : ((a + 1) / b) - 1);
          }

      Which would safe a cast in several common JSR-310 cases and also can intrinsify well

      Finally: Furthermore, a variant of multiplyExact with the signature (long, int) would be useful.

      This is by no means something that we require, but it would be nice to have it in 8 if there is still time and you figure that the motivation for it is strong enough. If not, feel free to defer.

      Thanks again for your prompt help with the other enhancements.


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bpb Brian Burkhalter
              Reporter:
              lagergren Marcus Lagergren
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: