Improve numerical code in StampedLock example code

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P4
    • 10
    • Affects Version/s: 10
    • Component/s: 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."

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

              Created:
              Updated:
              Resolved: