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

Improve numerical code in StampedLock example code

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 10
    • 10
    • core-libs

      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."

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

              Created:
              Updated:
              Resolved: