Package org.evoludo.math
Class Functions
Object
Functions
Collection of mathematical functions.
- Author:
- Christoph Hauert
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double
The maximum argument that the hyperbolic tangent can handle. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Ensure non-instantiability with private default constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic int
magnitude
(double value) Returns the order of magnitude ofvalue
.static double
round
(double value) Roundvalue
to next order of magnitude.static double
roundDown
(double value) Roundvalue
down to the next lower order of magnitude.static double
roundUp
(double value) Roundvalue
up to the next lower order of magnitude.static double
tanh
(double x) Returns the hyperbolic tangent of a double value.
-
Field Details
-
TANH_MAX_ARG
private static final double TANH_MAX_ARGThe maximum argument that the hyperbolic tangent can handle.- See Also:
-
-
Constructor Details
-
Functions
private Functions()Ensure non-instantiability with private default constructor
-
-
Method Details
-
round
public static double round(double value) Roundvalue
to next order of magnitude. For example, round 4 to 1 and 6 to 10.- Parameters:
value
- thedouble
to be rounded up- Returns:
- the rounded value
-
roundUp
public static double roundUp(double value) Roundvalue
up to the next lower order of magnitude. For example,2.51→3, 25.1→30, 251→260, 2510→2600, ...
- Parameters:
value
- thedouble
to be rounded up- Returns:
- the rounded value
-
roundDown
public static double roundDown(double value) Roundvalue
down to the next lower order of magnitude. For example,2.51→2, 25.1→20, 251→200, 2510→2000, ...
- Parameters:
value
- thedouble
to be rounded down- Returns:
- the rounded value
-
magnitude
public static int magnitude(double value) Returns the order of magnitude ofvalue
.- Parameters:
value
- the number to determine its order of magnitude- Returns:
- the order of magnitude
-
tanh
public static double tanh(double x) Returns the hyperbolic tangent of a double value. The hyperbolic tangent of \(x\) is defined to be \((e^x - e^{-x})/(e^x + e^{-x})\), in other words, \(\sinh(x)/\cosh(x)\). Note that the absolute value of the exact \(\tanh\) is always less than \(1\).Implementation Notes:
- GWT emulation of
Math.tanh(double)
is bad for largez
... should return1.0
instead ofDouble.NaN
! tanh
requires the calculation ofexp(2x)
but this returnsinfinity
in JavaScript ifx
is too large. Ensurex < Math.log(Double.MAX_VALUE) * 0.5
, which is \(\approx 350\).- Moreover,
tanh
calculations are only meaningful ifexp(2x)-1 != exp(2x)
, which results in a far lower threshold of merelyx < 19
.
- Parameters:
x
- thedouble
whose hyperbolic tangent to calculate- Returns:
- the hyperbolic tangent of
x
- See Also:
- GWT emulation of
-