|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.number.big.BigDecimalUtils
public class BigDecimalUtils
This class collects a set of utility functions for the java class BigDecimal.
| Field Summary | |
|---|---|
static java.math.BigDecimal |
PI
the value of PI |
| Method Summary | |
|---|---|
static int |
compare(java.math.BigDecimal n1,
java.math.BigDecimal n2,
int precision)
Compare two BigDecimals up to a precision. |
static boolean |
equals(java.math.BigDecimal n1,
java.math.BigDecimal n2,
int precision)
Compare two BigDecimals up to a precision. |
static java.math.BigDecimal |
exp(java.math.BigDecimal x)
Compute ex. |
static java.math.BigDecimal |
exp(java.math.BigDecimal x,
int scale)
Compute ex. |
static java.math.BigDecimal |
exp(double x)
Compute ex. |
static java.math.BigDecimal |
exp(double x,
int scale)
Compute ex. |
static java.math.BigDecimal |
getFractional(java.math.BigDecimal num)
Get the fractional part of this number. |
static java.math.BigDecimal |
getWhole(java.math.BigDecimal num)
Get the integral part of this number and discard the fractional part. |
static java.math.BigDecimal |
log(java.math.BigDecimal x)
Compute log(x). |
static java.math.BigDecimal |
log(java.math.BigDecimal x,
int scale)
Compute log(x) up to a scale. |
static java.math.BigDecimal |
pow(java.math.BigDecimal a,
java.math.BigDecimal b)
Compute a to the power of b. |
static java.math.BigDecimal |
pow(java.math.BigDecimal a,
java.math.BigDecimal b,
int scale)
Compute a to the power of b. |
static java.math.BigDecimal |
pow(java.math.BigDecimal a,
int b)
Compute a to the power of b where n is an integer. |
static java.math.BigDecimal |
pow(java.math.BigDecimal a,
int b,
int scale)
Compute a to the power of b where b is an integer. |
static java.math.BigDecimal |
sum(java.math.BigDecimal... big)
Compute the sum of an array of BigDecimals. |
static java.math.BigDecimal |
sum(double... big)
Compute the sum of an array of doubles. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.math.BigDecimal PI
| Method Detail |
|---|
public static int compare(java.math.BigDecimal n1,
java.math.BigDecimal n2,
int precision)
n1 - a BigDecimaln2 - a BigDecimalprecision - p; the threshold is 1e-p
n1 is numerically
less than, equal to, or greater than n2
public static boolean equals(java.math.BigDecimal n1,
java.math.BigDecimal n2,
int precision)
n1 - a BigDecimaln2 - a BigDecimalprecision - p; the threshold is 1e-p
true if the numbers are equal up to a precisionpublic static java.math.BigDecimal sum(java.math.BigDecimal... big)
big - an array of BigDecimals
public static java.math.BigDecimal sum(double... big)
This is done by first converting the doubles into BigDecimals,
and then apply BigDecimal.add(java.math.BigDecimal).
The accuracy is better than first adding them up as doubles and then convert the sum into BigDecimal.
big - an array of BigDecimals
public static java.math.BigDecimal getWhole(java.math.BigDecimal num)
num - a BigDecimal
public static java.math.BigDecimal getFractional(java.math.BigDecimal num)
For -ve. number, the fractional part is also -ve. For example, for -3.1415, the whole is -3 and the fractional part is -0.1415.
num - a BigDecimal
public static java.math.BigDecimal pow(java.math.BigDecimal a,
java.math.BigDecimal b)
a to the power of b.
a - the baseb - the exponent
ab
public static java.math.BigDecimal pow(java.math.BigDecimal a,
java.math.BigDecimal b,
int scale)
a to the power of b.
a - the baseb - the exponentscale - the scale for the BigDecimal result; a precision parameter
ab
public static java.math.BigDecimal pow(java.math.BigDecimal a,
int b)
a to the power of b where n is an integer.
a - the baseb - the exponent
ab
public static java.math.BigDecimal pow(java.math.BigDecimal a,
int b,
int scale)
a to the power of b where b is an integer.
This is simply a wrapper around BigDecimal.pow(int) but handles also negative exponents.
Use BigDecimal.pow(int) for arbitrary precision if the exponent is positive.
a - the baseb - the exponentscale - the scale for the BigDecimal result; a precision parameter
xnpublic static java.math.BigDecimal log(java.math.BigDecimal x)
log(x).
The base is e, hence the natural log.
x - x
log(x)
public static java.math.BigDecimal log(java.math.BigDecimal x,
int scale)
log(x) up to a scale.
The base is e, hence the natural log.
x - xscale - the scale for the BigDecimal result; a precision parameter
log(x)public static java.math.BigDecimal exp(double x)
ex.
x - the exponent
ex
public static java.math.BigDecimal exp(double x,
int scale)
ex.
x - the exponentscale - the scale for the BigDecimal result; a precision parameter
expublic static java.math.BigDecimal exp(java.math.BigDecimal x)
ex.
x - the exponent
ex
public static java.math.BigDecimal exp(java.math.BigDecimal x,
int scale)
ex.
x - the exponentscale - the scale for the BigDecimal result; a precision parameter
ex
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||