|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.ac.leeds.ccg.andyt.generic.math.Generic_Number
uk.ac.leeds.ccg.andyt.generic.math.Generic_BigDecimal
public class Generic_BigDecimal
For BigDecimal arithmetic. For the time being it is expected that BigDecimal numbers will not have a precision or scale greater than Integer.MAX_VALUE. Some of the functionality provided in this class may exist in third party libraries with appropriate licenses, but at the time of writing, I have not found them. The aim is for accuracy within a fixed number of decimal places. All methods need to be fully tested to ensure compliance...
Field Summary | |
---|---|
java.math.BigDecimal |
_E
For storing the Euler–Mascheroni constant correct to a fixed decimal place precision |
Generic_BigInteger |
_Factorial_Generic_BigInteger
Factorial of numbers are quite often wanted (especially in Taylor Series calculations), and when they are, this is for them. |
java.math.BigDecimal |
_PI
For storing the PI constant correct to a fixed decimal place precision |
java.math.RoundingMode |
_RoundingMode
RoundingMode used in calculations |
static java.math.BigDecimal |
Two
Two is quite often wanted as a BigDecimal so it is made available as a constant. |
Constructor Summary | |
---|---|
Generic_BigDecimal()
Creates a new instance of Generic_BigDecimal |
|
Generic_BigDecimal(int n)
|
Method Summary | |
---|---|
static java.math.BigDecimal |
ceilingSignificantDigit(java.math.BigDecimal x)
|
static java.math.BigDecimal |
divide(java.math.BigDecimal x,
java.math.BigDecimal y,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
|
static java.math.BigDecimal |
divide(java.math.BigDecimal x,
java.math.BigInteger y,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
|
static java.math.BigDecimal |
divide(java.math.BigInteger x,
java.math.BigDecimal y,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
|
static java.math.BigDecimal |
exp(java.math.BigDecimal x,
java.math.BigDecimal e,
Generic_BigDecimal a_Generic_BigDecimal,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
e^x = 1 + x/1! +x^2/2! + x^3/3! +... |
static java.math.BigDecimal |
floorSignificantDigit(java.math.BigDecimal x)
|
java.math.BigDecimal |
getE(int decimalPlaces)
|
java.math.BigDecimal |
getEMinDecimalPlaces(int decimalPlaces)
|
void |
init_E(int decimalPlaces)
|
void |
init_Factorial_Generic_BigInteger(int n)
|
void |
init_PI(int decimalPlaces)
|
static java.math.BigDecimal |
log(java.math.BigDecimal base,
java.math.BigDecimal x,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
Only works for x > 0. |
static java.math.BigDecimal |
log(int base_int,
java.math.BigDecimal x,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
Adapted from http://stackoverflow.com/questions/739532/logarithm-of-a-bigdecimal Pseudocode algorithm for doing a logarithm. |
static void |
main(java.lang.String[] args)
|
static java.math.BigDecimal |
max(java.math.BigDecimal x,
java.math.BigDecimal y)
|
static java.math.BigDecimal |
min(java.math.BigDecimal x,
java.math.BigDecimal y)
|
static java.math.BigDecimal |
multiply(java.math.BigDecimal x,
java.math.BigDecimal y,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
|
static java.math.BigDecimal |
multiply(java.math.BigDecimal x,
java.math.BigInteger y,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
|
static java.math.BigDecimal |
multiply(java.math.BigInteger x,
java.math.BigDecimal y,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
|
static java.math.BigDecimal |
newtonRaphson(java.math.BigDecimal x,
java.math.BigDecimal result0,
java.math.BigInteger root,
java.math.BigDecimal epsilon,
int maxite,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
Uses MathContext division |
static java.math.BigDecimal |
newtonRaphson0(java.math.BigDecimal x,
java.math.BigDecimal result0,
java.math.BigInteger root_BigInteger,
java.math.BigDecimal epsilon_BigDecimal,
int maxite,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
Uses decimalPlace division |
static java.math.BigDecimal |
power(java.math.BigDecimal x,
java.math.BigDecimal y,
java.math.BigDecimal e,
Generic_BigDecimal a_Generic_BigDecimal,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
x^y = e^(y * ln(x)) |
static java.math.BigDecimal |
power(java.math.BigDecimal x,
java.math.BigInteger y0,
int div,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
|
static java.math.BigDecimal |
power(java.math.BigDecimal x,
int y,
int div,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
|
static boolean |
powerTestAbove(java.math.BigDecimal compare,
java.math.BigDecimal x,
java.math.BigInteger y0,
int div,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
|
static boolean |
powerTestAbove(java.math.BigDecimal compare,
java.math.BigDecimal x,
int y,
int div,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
Deprecated. |
static boolean |
powerTestBelow(java.math.BigDecimal compare,
java.math.BigDecimal x,
java.math.BigInteger y0,
int div,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
|
static boolean |
powerTestBelow(java.math.BigDecimal compare,
java.math.BigDecimal x,
int y,
int div,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
Deprecated. |
static java.math.BigDecimal |
reciprocal(java.math.BigDecimal x,
int decimalPlace,
java.math.RoundingMode a_RoundingMode)
|
static java.math.BigInteger |
reciprocalWillBeInteger(java.math.BigDecimal x)
|
static java.math.BigDecimal |
root(java.math.BigDecimal x,
java.math.BigInteger root,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
|
static java.math.BigDecimal |
root(java.math.BigDecimal x,
int root,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
|
static java.math.BigDecimal |
round(java.math.BigDecimal x,
int decimalPlaces,
java.math.RoundingMode a_RoundingMode)
If x is rounded to a BigDecimal equivalent to 0, the trailing Zeros are not stripped! |
static java.math.BigDecimal |
sqrt0(java.math.BigDecimal input,
int decimalPlaces)
Returns the square root of the input BigDecimal as a BigDecimal. |
Methods inherited from class uk.ac.leeds.ccg.andyt.generic.math.Generic_Number |
---|
timeReport |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public Generic_BigInteger _Factorial_Generic_BigInteger
public java.math.BigDecimal _E
public java.math.BigDecimal _PI
public java.math.RoundingMode _RoundingMode
public static final java.math.BigDecimal Two
Constructor Detail |
---|
public Generic_BigDecimal()
public Generic_BigDecimal(int n)
Method Detail |
---|
public final void init_Factorial_Generic_BigInteger(int n)
public final void init_E(int decimalPlaces)
public final void init_PI(int decimalPlaces)
public static void main(java.lang.String[] args)
args
- the command line argumentspublic static java.math.BigDecimal multiply(java.math.BigDecimal x, java.math.BigDecimal y, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- y
- decimalPlaces
- a_RoundingMode
-
public static java.math.BigDecimal multiply(java.math.BigDecimal x, java.math.BigInteger y, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- y
- decimalPlaces
- a_RoundingMode
-
public static java.math.BigDecimal multiply(java.math.BigInteger x, java.math.BigDecimal y, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- y
- decimalPlaces
- a_RoundingMode
-
public static java.math.BigDecimal divide(java.math.BigDecimal x, java.math.BigDecimal y, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- y
- decimalPlaces
- a_RoundingMode
-
public static java.math.BigDecimal divide(java.math.BigDecimal x, java.math.BigInteger y, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- y
- decimalPlaces
- a_RoundingMode
-
public static java.math.BigDecimal divide(java.math.BigInteger x, java.math.BigDecimal y, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
public static boolean powerTestAbove(java.math.BigDecimal compare, java.math.BigDecimal x, java.math.BigInteger y0, int div, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
compare
- x
- x > 1y0
- y0 > 1div
- Optimisation parameter...decimalPlaces
- The number of decimal places rounded to if rounding
is necessary.a_RoundingMode
- The RoundingMode used in the case rounding is
necessary.
public static boolean powerTestBelow(java.math.BigDecimal compare, java.math.BigDecimal x, java.math.BigInteger y0, int div, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
compare
- x
- x > 0y0
- y0 > 1div
- Optimisation parameter...decimalPlaces
- The number of decimal places rounded to if rounding
is necessary.a_RoundingMode
- The RoundingMode used in the case rounding is
necessary.
@Deprecated public static boolean powerTestAbove(java.math.BigDecimal compare, java.math.BigDecimal x, int y, int div, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- x > 1y
- x > 1div
- If < 3 this is set to 2. If > 256 set to 256decimalPlaces
- a_RoundingMode
-
@Deprecated public static boolean powerTestBelow(java.math.BigDecimal compare, java.math.BigDecimal x, int y, int div, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- x > 0y
- x > 1div
- If < 3 this is set to 2. If > 256 set to 256decimalPlaces
- a_RoundingMode
-
public static java.math.BigDecimal power(java.math.BigDecimal x, java.math.BigDecimal y, java.math.BigDecimal e, Generic_BigDecimal a_Generic_BigDecimal, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- y
- decimalPlaces
- The number of decimal places the toCompare must be
accurate and rounded to if necessary.
public static java.math.BigDecimal power(java.math.BigDecimal x, int y, int div, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- y
- div
- If div < 2 it is set to 2. If div > 256 it is set to 256.decimalPlaces
- a_RoundingMode
-
public static java.math.BigDecimal power(java.math.BigDecimal x, java.math.BigInteger y0, int div, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- y0
- div
- If div < 2 it is set to 2. If div > 256 it is set to 256.decimalPlaces
- a_RoundingMode
-
public static java.math.BigDecimal reciprocal(java.math.BigDecimal x, int decimalPlace, java.math.RoundingMode a_RoundingMode)
x
- decimalPlace
- a_RoundingMode
-
public static java.math.BigInteger reciprocalWillBeInteger(java.math.BigDecimal x)
x
-
public static java.math.BigDecimal log(int base_int, java.math.BigDecimal x, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
public static java.math.BigDecimal log(java.math.BigDecimal base, java.math.BigDecimal x, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
base
- x
- decimalPlaces
- a_RoundingMode
-
public static java.math.BigDecimal round(java.math.BigDecimal x, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- decimalPlaces
- a_RoundingMode
-
public java.math.BigDecimal getEMinDecimalPlaces(int decimalPlaces)
public java.math.BigDecimal getE(int decimalPlaces)
public static java.math.BigDecimal exp(java.math.BigDecimal x, java.math.BigDecimal e, Generic_BigDecimal a_Generic_BigDecimal, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- decimalPlaces
-
public static java.math.BigDecimal max(java.math.BigDecimal x, java.math.BigDecimal y)
x
- y
-
public static java.math.BigDecimal min(java.math.BigDecimal x, java.math.BigDecimal y)
x
- y
-
public static java.math.BigDecimal floorSignificantDigit(java.math.BigDecimal x)
public static java.math.BigDecimal ceilingSignificantDigit(java.math.BigDecimal x)
public static java.math.BigDecimal root(java.math.BigDecimal x, java.math.BigInteger root, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- root
- decimalPlaces
- a_RoundingMode
-
public static java.math.BigDecimal newtonRaphson(java.math.BigDecimal x, java.math.BigDecimal result0, java.math.BigInteger root, java.math.BigDecimal epsilon, int maxite, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- result0
- root
- epsilon
- maxite
- decimalPlaces
- a_RoundingMode
-
public static java.math.BigDecimal newtonRaphson0(java.math.BigDecimal x, java.math.BigDecimal result0, java.math.BigInteger root_BigInteger, java.math.BigDecimal epsilon_BigDecimal, int maxite, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- result0
- root_BigInteger
- epsilon_BigDecimal
- maxite
- decimalPlaces
- a_RoundingMode
-
public static java.math.BigDecimal root(java.math.BigDecimal x, int root, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
x
- x >= 0root
- decimalPlaces
- a_RoundingMode
-
public static java.math.BigDecimal sqrt0(java.math.BigDecimal input, int decimalPlaces)
input
- decimalPlaces
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |