Package org.djutils.complex.demo
Class PerformanceTests
- java.lang.Object
-
- org.djutils.complex.demo.PerformanceTests
-
public final class PerformanceTests extends Object
PerformanceTests.java.
Copyright (c) 2020-2020 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
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; xy
- double; y- Returns:
- double; the hypot of x, and y
-
hypotB
public static double hypotB(double x, double y)
hypot.- Parameters:
x
- double; xy
- 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)
-
-