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

Improve numerical code in StampedLock example code

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 10
    • Fix Version/s: 10
    • Component/s: core-libs
    • Labels:

      Description

      The StampedLock class has some sample code with a distanceFromOrigin() method. The sample code uses

      return Math.sqrt(currentX * currentX + currentY * currentY);

      to compute the Euclidean distance. From a numerical perspective, this would be better computed using Math.hypot or StrictMath.hypot. The hypot method "Returns sqrt(x^2 +y^2) without intermediate overflow or underflow."

        Attachments

          Activity

            People

            Assignee:
            martin Martin Buchholz
            Reporter:
            darcy Joe Darcy
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: