Class DfpMath


  • public class DfpMath
    extends java.lang.Object
    Mathematical routines for use with Dfp. The constants are defined in DfpField
    Since:
    2.2
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Dfp acos​(Dfp a)
      computes the arc-cosine of the argument.
      static Dfp asin​(Dfp a)
      computes the arc-sine of the argument.
      static Dfp atan​(Dfp a)
      computes the arc tangent of the argument Uses the typical taylor series but may reduce arguments using the following identity tan(x+y) = (tan(x) + tan(y)) / (1 - tan(x)*tan(y)) since tan(PI/8) = sqrt(2)-1, atan(x) = atan( (x - sqrt(2) + 1) / (1+x*sqrt(2) - x) + PI/8.0
      static Dfp cos​(Dfp a)
      computes the cosine of the argument.
      static Dfp exp​(Dfp a)
      Computes e to the given power.
      static Dfp log​(Dfp a)
      Returns the natural logarithm of a.
      static Dfp pow​(Dfp base, int a)
      Raises base to the power a by successive squaring.
      static Dfp pow​(Dfp x, Dfp y)
      Computes x to the y power.
      static Dfp sin​(Dfp a)
      computes the sine of the argument.
      static Dfp tan​(Dfp a)
      computes the tangent of the argument.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • pow

        public static Dfp pow​(Dfp base,
                              int a)
        Raises base to the power a by successive squaring.
        Parameters:
        base - number to raise
        a - power
        Returns:
        basea
      • exp

        public static Dfp exp​(Dfp a)
        Computes e to the given power. a is broken into two parts, such that a = n+m where n is an integer. We use pow() to compute en and a Taylor series to compute em. We return e*n × em
        Parameters:
        a - power at which e should be raised
        Returns:
        ea
      • log

        public static Dfp log​(Dfp a)
        Returns the natural logarithm of a. a is first split into three parts such that a = (10000^h)(2^j)k. ln(a) is computed by ln(a) = ln(5)*h + ln(2)*(h+j) + ln(k) k is in the range 2/3 < k <4/3 and is passed on to a series expansion.
        Parameters:
        a - number from which logarithm is requested
        Returns:
        log(a)
      • pow

        public static Dfp pow​(Dfp x,
                              Dfp y)
        Computes x to the y power.

        Uses the following method:

        1. Set u = rint(y), v = y-u
        2. Compute a = v * ln(x)
        3. Compute b = rint( a/ln(2) )
        4. Compute c = a - b*ln(2)
        5. xy = xu * 2b * ec
        if |y| > 1e8, then we compute by exp(y*ln(x))

        Special Cases

        • if y is 0.0 or -0.0 then result is 1.0
        • if y is 1.0 then result is x
        • if y is NaN then result is NaN
        • if x is NaN and y is not zero then result is NaN
        • if |x| > 1.0 and y is +Infinity then result is +Infinity
        • if |x| < 1.0 and y is -Infinity then result is +Infinity
        • if |x| > 1.0 and y is -Infinity then result is +0
        • if |x| < 1.0 and y is +Infinity then result is +0
        • if |x| = 1.0 and y is +/-Infinity then result is NaN
        • if x = +0 and y > 0 then result is +0
        • if x = +Inf and y < 0 then result is +0
        • if x = +0 and y < 0 then result is +Inf
        • if x = +Inf and y > 0 then result is +Inf
        • if x = -0 and y > 0, finite, not odd integer then result is +0
        • if x = -0 and y < 0, finite, and odd integer then result is -Inf
        • if x = -Inf and y > 0, finite, and odd integer then result is -Inf
        • if x = -0 and y < 0, not finite odd integer then result is +Inf
        • if x = -Inf and y > 0, not finite odd integer then result is +Inf
        • if x < 0 and y > 0, finite, and odd integer then result is -(|x|y)
        • if x < 0 and y > 0, finite, and not integer then result is NaN
        Parameters:
        x - base to be raised
        y - power to which base should be raised
        Returns:
        xy
      • sin

        public static Dfp sin​(Dfp a)
        computes the sine of the argument.
        Parameters:
        a - number from which sine is desired
        Returns:
        sin(a)
      • cos

        public static Dfp cos​(Dfp a)
        computes the cosine of the argument.
        Parameters:
        a - number from which cosine is desired
        Returns:
        cos(a)
      • tan

        public static Dfp tan​(Dfp a)
        computes the tangent of the argument.
        Parameters:
        a - number from which tangent is desired
        Returns:
        tan(a)
      • atan

        public static Dfp atan​(Dfp a)
        computes the arc tangent of the argument Uses the typical taylor series but may reduce arguments using the following identity tan(x+y) = (tan(x) + tan(y)) / (1 - tan(x)*tan(y)) since tan(PI/8) = sqrt(2)-1, atan(x) = atan( (x - sqrt(2) + 1) / (1+x*sqrt(2) - x) + PI/8.0
        Parameters:
        a - number from which arc-tangent is desired
        Returns:
        atan(a)
      • asin

        public static Dfp asin​(Dfp a)
        computes the arc-sine of the argument.
        Parameters:
        a - number from which arc-sine is desired
        Returns:
        asin(a)
      • acos

        public static Dfp acos​(Dfp a)
        computes the arc-cosine of the argument.
        Parameters:
        a - number from which arc-cosine is desired
        Returns:
        acos(a)