Package org.evoludo.math
Class Functions
Object
Functions
Collection of mathematical functions.
- Author:
- Christoph Hauert
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final doubleThe maximum argument that the hyperbolic tangent can handle. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateEnsure non-instantiability with private default constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic intmagnitude(double value) Returns the order of magnitude ofvalue.static doubleround(double value) Roundvalueto next order of magnitude.static doubleroundDown(double value) Roundvaluedown to the next lower order of magnitude.static doubleroundUp(double value) Roundvalueup to the next lower order of magnitude.static doubletanh(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) Roundvalueto next order of magnitude. For example, round 4 to 1 and 6 to 10.- Parameters:
value- thedoubleto be rounded up- Returns:
- the rounded value
-
roundUp
public static double roundUp(double value) Roundvalueup to the next lower order of magnitude. For example,2.51→3, 25.1→30, 251→260, 2510→2600, ...- Parameters:
value- thedoubleto be rounded up- Returns:
- the rounded value
-
roundDown
public static double roundDown(double value) Roundvaluedown to the next lower order of magnitude. For example,2.51→2, 25.1→20, 251→200, 2510→2000, ...- Parameters:
value- thedoubleto 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.0instead ofDouble.NaN! tanhrequires the calculation ofexp(2x)but this returnsinfinityin JavaScript ifxis too large. Ensurex < Math.log(Double.MAX_VALUE) * 0.5, which is \(\approx 350\).- Moreover,
tanhcalculations are only meaningful ifexp(2x)-1 != exp(2x), which results in a far lower threshold of merelyx < 19.
- Parameters:
x- thedoublewhose hyperbolic tangent to calculate- Returns:
- the hyperbolic tangent of
x - See Also:
- GWT emulation of
-