Class Functions

Object
Functions

public class Functions extends Object
Collection of mathematical functions.
Author:
Christoph Hauert
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final double
    The maximum argument that the hyperbolic tangent can handle.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Ensure non-instantiability with private default constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    magnitude(double value)
    Returns the order of magnitude of value.
    static double
    round(double value)
    Round value to next order of magnitude.
    static double
    roundDown(double value)
    Round value down to the next lower order of magnitude.
    static double
    roundUp(double value)
    Round value up to the next lower order of magnitude.
    static double
    tanh(double x)
    Returns the hyperbolic tangent of a double value.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TANH_MAX_ARG

      private static final double TANH_MAX_ARG
      The 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)
      Round value to next order of magnitude. For example, round 4 to 1 and 6 to 10.
      Parameters:
      value - the double to be rounded up
      Returns:
      the rounded value
    • roundUp

      public static double roundUp(double value)
      Round value up to the next lower order of magnitude. For example, 2.51→3, 25.1→30, 251→260, 2510→2600, ...
      Parameters:
      value - the double to be rounded up
      Returns:
      the rounded value
    • roundDown

      public static double roundDown(double value)
      Round value down to the next lower order of magnitude. For example, 2.51→2, 25.1→20, 251→200, 2510→2000, ...
      Parameters:
      value - the double to be rounded down
      Returns:
      the rounded value
    • magnitude

      public static int magnitude(double value)
      Returns the order of magnitude of value.
      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 large z... should return 1.0 instead of Double.NaN!
      • tanh requires the calculation of exp(2x) but this returns infinity in JavaScript if x is too large. Ensure x < Math.log(Double.MAX_VALUE) * 0.5, which is \(\approx 350\).
      • Moreover, tanh calculations are only meaningful if exp(2x)-1 != exp(2x), which results in a far lower threshold of merely x < 19.
      Parameters:
      x - the double whose hyperbolic tangent to calculate
      Returns:
      the hyperbolic tangent of x
      See Also: