Package org.djutils.complex.demo
Class PerformanceTests
java.lang.Object
org.djutils.complex.demo.PerformanceTests
PerformanceTests.java.
Copyright (c) 2020-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.
Copyright (c) 2020-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.
- Author:
- Alexander Verbraeck, Peter Knoppers
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
hypotA
(double px, double py) Implementation of hypot taken from https://stackoverflow.com/questions/3764978/why-hypot-function-is-so-slow .static double
hypotB
(double px, double py) 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
Measure performance of atan2, hypot, sine and cosine.
-
Method Details
-
main
Measure performance of atan2, hypot, sine and cosine.- Parameters:
args
- String[]; the command line arguments (not used)
-
hypotA
public static double hypotA(double px, double py) Implementation of hypot taken from https://stackoverflow.com/questions/3764978/why-hypot-function-is-so-slow .- Parameters:
px
- double; xpy
- double; y- Returns:
- double; the hypot of x, and y
-
hypotB
public static double hypotB(double px, double py) hypot.- Parameters:
px
- double; xpy
- 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 valuey
- double; the y value- Returns:
- double; hypot(x, y)
-