rossi.dfp
Class dfpmath

java.lang.Object
  |
  +--rossi.dfp.dfpmath
All Implemented Interfaces:
dfpconstants

public class dfpmath
extends java.lang.Object
implements dfpconstants

Mathematical routines and constants for use with dfp. Constants are defined with in dfpconstants.java


Field Summary
static dfp E
          E
static dfp[] E_SPLIT
          E_SPLIT The number e split in two pieces
static dfp LN10
          ln(10)
static dfp LN2
          ln(2)
static dfp[] LN2_SPLIT
          LN2_SPLIT The number e split in two pieces
static dfp LN5
          ln(5)
static dfp[] LN5_SPLIT
          LN5_SPLIT The number e split in two pieces
static dfp PI
          PI
static dfp[] PI_SPLIT
          PI_SPLIT in 2 pieces
static dfp SQR2
          sqrt(2)
static dfp SQR2_2
          sqrt(2)/2
static dfp[] SQR2_SPLIT
          sqrt(2) in 2 pieces
static dfp SQR3
          sqrt(3)
static dfp SQR3_3
          sqrt(3)/3
 
Fields inherited from interface rossi.dfp.dfpconstants
STR_E, STR_LN10, STR_LN2, STR_LN5, STR_PI, STR_SQR2, STR_SQR2_2, STR_SQR3, STR_SQR3_3
 
Constructor Summary
dfpmath()
           
 
Method Summary
static dfp acos(dfp a)
           
static dfp asin(dfp a)
           
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
protected static dfp atanInternal(dfp a)
           
static dfp cos(dfp a)
          computes the cosine of the argument
protected static dfp cosInternal(dfp[] a)
          Computes cos(a) Used when 0 < a < pi/4.
static dfp exp(dfp a)
          Computes e to the given power.
protected static dfp expInternal(dfp a)
          Computes e to the given power.
static dfp ln(dfp a)
          Returns the natural logarithm of a.
protected static dfp[] lnInternal(dfp[] a)
          Computes the natural log of a number between 0 and 2
static dfp pow(dfp x, dfp y)
          Computes x to the y power.
static dfp pow(dfp base, int a)
          Raises base to the power a by successive squaring
static dfp sin(dfp a)
          computes the sine of the argument
protected static dfp sinInternal(dfp[] a)
          Computes sin(a) Used when 0 < a < pi/4.
protected static dfp[] split(dfp a)
          Splits a dfp into 2 dfp's such that their sum is equal to the input dfp
protected static dfp[] split(java.lang.String a)
          Breaks a string representation up into two dfp's such that the sum of them is equivilent to the input string, but has higher precision than using a single dfp.
protected static dfp[] splitDiv(dfp[] a, dfp[] b)
          Divide two numbers that are split in to two pices that are meant to be added together.
protected static dfp[] splitMult(dfp[] a, dfp[] b)
          Multiply two numbers that are split in to two pices that are meant to be added together.
protected static dfp splitPow(dfp[] base, int a)
          Raise a split base to the a power.
static dfp tan(dfp a)
          computes the tangent of the argument
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SQR2

public static final dfp SQR2
sqrt(2)


SQR2_SPLIT

public static final dfp[] SQR2_SPLIT
sqrt(2) in 2 pieces


SQR2_2

public static final dfp SQR2_2
sqrt(2)/2


SQR3

public static final dfp SQR3
sqrt(3)


SQR3_3

public static final dfp SQR3_3
sqrt(3)/3


PI

public static final dfp PI
PI


PI_SPLIT

public static final dfp[] PI_SPLIT
PI_SPLIT in 2 pieces


E

public static final dfp E
E


E_SPLIT

public static final dfp[] E_SPLIT
E_SPLIT The number e split in two pieces


LN2

public static final dfp LN2
ln(2)


LN2_SPLIT

public static final dfp[] LN2_SPLIT
LN2_SPLIT The number e split in two pieces


LN5

public static final dfp LN5
ln(5)


LN5_SPLIT

public static final dfp[] LN5_SPLIT
LN5_SPLIT The number e split in two pieces


LN10

public static final dfp LN10
ln(10)

Constructor Detail

dfpmath

public dfpmath()
Method Detail

split

protected static dfp[] split(java.lang.String a)
Breaks a string representation up into two dfp's such that the sum of them is equivilent to the input string, but has higher precision than using a single dfp. Useful for improving accuracy of exponentination and critical multplies


split

protected static dfp[] split(dfp a)
Splits a dfp into 2 dfp's such that their sum is equal to the input dfp


splitMult

protected static dfp[] splitMult(dfp[] a,
                                 dfp[] b)
Multiply two numbers that are split in to two pices that are meant to be added together. Use binomail multiplication so ab = a0 b0 + a0 b1 + a1 b0 + a1 b1 Store the first term in result0, the rest in result1


splitDiv

protected static dfp[] splitDiv(dfp[] a,
                                dfp[] b)
Divide two numbers that are split in to two pices that are meant to be added together. Inverse of split mult above: (a+b) / (c+d) = (a/c) + ( (bc-ad)/(c**2+cd) )


splitPow

protected static dfp splitPow(dfp[] base,
                              int a)
Raise a split base to the a power. return a combined result


pow

public static dfp pow(dfp base,
                      int a)
Raises base to the power a by successive squaring


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 e**n and a taylor series to compute e**m. We return (e**n)(e**m)


expInternal

protected static dfp expInternal(dfp a)
Computes e to the given power. Where -1 < a < 1. Use the classic Taylor series. 1 + x**2/2! + x**3/3! + x**4/4! ...


ln

public static dfp ln(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.


lnInternal

protected static dfp[] lnInternal(dfp[] a)
Computes the natural log of a number between 0 and 2


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


sinInternal

protected static dfp sinInternal(dfp[] a)
Computes sin(a) Used when 0 < a < pi/4. Uses the classic Taylor series. x - x**3/3! + x**5/5! ...


cosInternal

protected static dfp cosInternal(dfp[] a)
Computes cos(a) Used when 0 < a < pi/4. Uses the classic Taylor series for cosine. 1 - x**2/2! + x**4/4! ...


sin

public static dfp sin(dfp a)
computes the sine of the argument


cos

public static dfp cos(dfp a)
computes the cosine of the argument


tan

public static dfp tan(dfp a)
computes the tangent of the argument


atanInternal

protected static dfp atanInternal(dfp 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


asin

public static dfp asin(dfp a)

acos

public static dfp acos(dfp a)