Class PerformanceTests

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double hypotA​(double x, double y)
      Implementation of hypot taken from https://stackoverflow.com/questions/3764978/why-hypot-function-is-so-slow .
      static double hypotB​(double x, double y)
      hypot.
      static double hypotC​(double x, double y)
      Better implementation of the hypotenuse function (faster and more accurate than the one in the java Math library).
      static void main​(String[] args)
      Measure performance of atan2, hypot, sine and cosine.
    • Method Detail

      • main

        public static void main​(String[] args)
        Measure performance of atan2, hypot, sine and cosine.
        Parameters:
        args - String[]; the command line arguments (not used)
      • hypotA

        public static double hypotA​(double x,
                                    double y)
        Implementation of hypot taken from https://stackoverflow.com/questions/3764978/why-hypot-function-is-so-slow .
        Parameters:
        x - double; x
        y - double; y
        Returns:
        double; the hypot of x, and y
      • hypotB

        public static double hypotB​(double x,
                                    double y)
        hypot.
        Parameters:
        x - double; x
        y - double; y
        Returns:
        sqrt(x*x +y*y) without intermediate overflow or underflow. Note Math.hypot(double, double) is unnecessarily slow. This returns the identical result to Math.hypot with reasonable run times (~40 nsec vs. 800 nsec). The logic for computing z is copied from "Freely Distributable Math Library" fdlibm's e_hypot.c. This minimizes rounding error to provide 1 ulb accuracy.
      • hypotC

        public static double hypotC​(double x,
                                    double y)
        Better implementation of the hypotenuse function (faster and more accurate than the one in the java Math library).
        Derived from An improved algorithm for hypot(a, b) by Carlos F. Borges.
        Parameters:
        x - double; the x value
        y - double; the y value
        Returns:
        double; hypot(x, y)