public final class BigDecimalUtils extends Object
BigDecimal
.Modifier and Type | Field and Description |
---|---|
static BigDecimal |
PI
the value of PI
|
Modifier and Type | Method and Description |
---|---|
static int |
compare(BigDecimal n1,
BigDecimal n2,
int p)
Compare two
BigDecimal s up to a precision. |
static boolean |
equals(BigDecimal n1,
BigDecimal n2,
int precision)
Check if two
BigDecimal s are equal up to a precision. |
static BigDecimal |
exp(BigDecimal x)
Compute ex.
|
static BigDecimal |
exp(BigDecimal x,
int scale)
Compute ex.
|
static BigDecimal |
exp(double x)
Compute ex.
|
static BigDecimal |
exp(double x,
int scale)
Compute ex.
|
static BigDecimal |
getFractional(BigDecimal num)
Get the fractional part of a number.
|
static BigDecimal |
getWhole(BigDecimal num)
Get the integral part of a number (discarding the fractional part).
|
static BigDecimal |
log(BigDecimal x)
Compute log(x).
|
static BigDecimal |
log(BigDecimal x,
int scale)
Compute log(x) up to a scale.
|
static BigDecimal |
pow(BigDecimal a,
BigDecimal b)
Compute a to the power of b.
|
static BigDecimal |
pow(BigDecimal a,
BigDecimal b,
int scale)
Compute a to the power of b.
|
static BigDecimal |
pow(BigDecimal a,
int n)
Compute a to the power of n, where n is an integer.
|
static BigDecimal |
pow(BigDecimal a,
int n,
int scale)
Compute a to the power of n, where n is an integer.
|
static BigDecimal |
sum(BigDecimal... big)
Sum up the
BigDecimal numbers. |
static BigDecimal |
sum(double... big)
Sum up big numbers.
|
public static final BigDecimal PI
public static int compare(BigDecimal n1, BigDecimal n2, int p)
BigDecimal
s up to a precision.
In other words, if the absolute difference between the two numbers falls below a threshold, they are considered equal.n1
- a BigDecimal
n2
- a BigDecimal
p
- the threshold is 1e-pn1
is numerically less than, equal to, or greater than n2
, respectivelypublic static boolean equals(BigDecimal n1, BigDecimal n2, int precision)
BigDecimal
s are equal up to a precision.n1
- a BigDecimal
n2
- a BigDecimal
precision
- the threshold is 1e-ptrue
if the numbers are equal up to a precisionpublic static BigDecimal sum(BigDecimal... big)
BigDecimal
numbers.big
- BigDecimal
numberspublic static BigDecimal sum(double... big)
big
- numberspublic static BigDecimal getWhole(BigDecimal num)
num
- a BigDecimal
public static BigDecimal getFractional(BigDecimal num)
num
- a BigDecimal
public static BigDecimal pow(BigDecimal a, BigDecimal b)
a
- a baseb
- an exponentpublic static BigDecimal pow(BigDecimal a, BigDecimal b, int scale)
a
- a baseb
- an exponentscale
- a precision parameter as in BigDecimal
public static BigDecimal pow(BigDecimal a, int n)
a
- a basen
- an integer exponentpublic static BigDecimal pow(BigDecimal a, int n, int scale)
BigDecimal.pow(int)
but handles also negative exponents.
Use BigDecimal.pow(int)
for arbitrary precision if the exponent is positive.a
- a basen
- an exponentscale
- a precision parameter as in BigDecimal
public static BigDecimal log(BigDecimal x)
x
- a numberpublic static BigDecimal log(BigDecimal x, int scale)
x
- a numberscale
- a precision parameter as in BigDecimal
public static BigDecimal exp(double x)
x
- the exponentpublic static BigDecimal exp(double x, int scale)
x
- the exponentscale
- a precision parameter as in BigDecimal
public static BigDecimal exp(BigDecimal x)
x
- the exponentpublic static BigDecimal exp(BigDecimal x, int scale)
x
- the exponentscale
- a precision parameter as in BigDecimal
Copyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.