public class BigFloat extends java.lang.Object implements java.lang.Comparable<BigFloat>
BigDecimal which simplifies the consistent usage of the MathContext
and provides a simpler API for calculations.
Every BigFloat instance has a reference to a BigFloat.Context that specifies the MathContext to be used for all calculations and values.
The API for calculations is simplified and more consistent with the typical mathematical usage.
valueOf(BigFloat)valueOf(BigDecimal)valueOf(int)valueOf(long)valueOf(double)valueOf(String)pi()e()add(x)subtract(x)multiply(x)remainder(x)pow(y)root(y)add(BigFloat)add(BigDecimal)add(int)add(long)add(double)abs(x)log(x)sin(x)min(x1, x2, ...)max(x1, x2, ...)sqrt(x)log(x)exp(x)sin(x)cos(x)tan(x)getMantissa()getExponent()getIntegralPart()getFractionalPart()equals(Object) that returns whether two BigFloat values are mathematically the samehashCode() consistent with equals(Object)isEqual(BigFloat)isLessThan(BigFloat)isLessThanOrEqual(BigFloat)isGreaterThan(BigFloat)isGreaterThanOrEqual(BigFloat)Before doing any calculations you need to create a Context specifying the precision used for all calculations.
Context context = BigFloat.context(100); // precision of 100 digits Context anotherContext = BigFloat.context(new MathContext(10, RoundingMode.HALF_UP); // precision of 10 digits, rounding half up
The Context can then be used to create the first value of the calculation:
BigFloat value1 = context.valueOf(640320);
The BigFloat instance holds a reference to the Context. This context is then passed from calculation to calculation.
BigFloat value2 = context.valueOf(640320).pow(3).divide(24); BigFloat value3 = BigFloat.sin(value2);
The BigFloat result can be converted to other numerical types:
BigDecimal bigDecimalValue = value3.toBigDecimal(); double doubleValue = value3.toDouble(); long longValue = value3.toLong(); int intValue = value3.toInt();
| Modifier and Type | Class and Description |
|---|---|
static class |
BigFloat.Context
Manages the
MathContext and provides factory methods for BigFloat values. |
| Modifier and Type | Method and Description |
|---|---|
static BigFloat |
abs(BigFloat x)
Returns the
BigFloat that is the abs(this) (absolute value). |
static BigFloat |
acos(BigFloat x)
Returns the
BigFloat that is acos(x). |
static BigFloat |
acosh(BigFloat x)
Returns the
BigFloat that is acosh(x). |
static BigFloat |
acot(BigFloat x)
Returns the
BigFloat that is acot(x). |
static BigFloat |
acoth(BigFloat x)
Returns the
BigFloat that is acoth(x). |
BigFloat |
add(java.math.BigDecimal x)
Returns the
BigFloat that is this + x. |
BigFloat |
add(BigFloat x)
Returns the
BigFloat that is this + x. |
BigFloat |
add(double x)
Returns the
BigFloat that is this + x. |
BigFloat |
add(int x)
Returns the
BigFloat that is this + x. |
BigFloat |
add(long x)
Returns the
BigFloat that is this + x. |
static BigFloat |
asin(BigFloat x)
Returns the
BigFloat that is asin(x). |
static BigFloat |
asinh(BigFloat x)
Returns the
BigFloat that is asinh(x). |
static BigFloat |
atan(BigFloat x)
Returns the
BigFloat that is atan(x). |
static BigFloat |
atanh(BigFloat x)
Returns the
BigFloat that is atanh(x). |
int |
compareTo(BigFloat other) |
static BigFloat.Context |
context(int precision)
Creates a
BigFloat.Context with the specified precision and RoundingMode.HALF_UP rounding. |
static BigFloat.Context |
context(java.math.MathContext mathContext)
Creates a
BigFloat.Context with the specified MathContext. |
static BigFloat |
cos(BigFloat x)
Returns the
BigFloat that is cos(x). |
static BigFloat |
cosh(BigFloat x)
Returns the
BigFloat that is cosh(x). |
static BigFloat |
cot(BigFloat x)
Returns the
BigFloat that is cot(x). |
static BigFloat |
coth(BigFloat x)
Returns the
BigFloat that is coth(x). |
BigFloat |
divide(java.math.BigDecimal x)
Returns the
BigFloat that is this / x. |
BigFloat |
divide(BigFloat x)
Returns the
BigFloat that is this / x. |
BigFloat |
divide(double x)
Returns the
BigFloat that is this / x. |
BigFloat |
divide(int x)
Returns the
BigFloat that is this / x. |
BigFloat |
divide(long x)
Returns the
BigFloat that is this / x. |
boolean |
equals(java.lang.Object obj) |
static BigFloat |
exp(BigFloat x)
Returns the
BigFloat that is exp(x). |
BigFloat.Context |
getContext()
Returns the
BigFloat.Context of this value. |
BigFloat |
getExponent()
Returns the exponent of
this value written as mantissa * 10exponent. |
BigFloat |
getFractionalPart()
Returns the fractional part of
this value (right of the decimal point). |
BigFloat |
getIntegralPart()
Returns the integral part of
this value (left of the decimal point). |
BigFloat |
getMantissa()
Returns the mantissa of
this value written as mantissa * 10exponent. |
int |
hashCode() |
boolean |
isDoubleValue()
Returns whether
this specified BigDecimal value can be represented as double. |
boolean |
isEqual(BigFloat other)
Returns whether
this value is mathematically equal to the other value. |
boolean |
isGreaterThan(BigFloat other)
Returns whether
this value is mathematically greater than to the other value. |
boolean |
isGreaterThanOrEqual(BigFloat other)
Returns whether
this value is mathematically greater than or equal to the other value. |
boolean |
isIntValue()
Returns whether
this value can be represented as int. |
boolean |
isLessThan(BigFloat other)
Returns whether
this value is mathematically less than to the other value. |
boolean |
isLessThanOrEqual(BigFloat other)
Returns whether
this value is mathematically less than or equal to the other value. |
boolean |
isNegative()
Returns whether this
BigFloat is negative. |
boolean |
isPositive()
Returns whether this
BigFloat is positive. |
boolean |
isZero()
Returns whether this
BigFloat is 0. |
static BigFloat |
log(BigFloat x)
Returns the
BigFloat that is log(x). |
static BigFloat |
log10(BigFloat x)
Returns the
BigFloat that is log10(x). |
static BigFloat |
log2(BigFloat x)
Returns the
BigFloat that is log2(x). |
static BigFloat |
max(BigFloat value1,
BigFloat... values)
Returns the the maximum of n
BigFloat values. |
static BigFloat |
max(BigFloat value1,
BigFloat value2)
Returns the the maximum of two
BigFloat values. |
static BigFloat |
min(BigFloat value1,
BigFloat... values)
Returns the the minimum of n
BigFloat values. |
static BigFloat |
min(BigFloat value1,
BigFloat value2)
Returns the the minimum of two
BigFloat values. |
BigFloat |
multiply(java.math.BigDecimal x)
Returns the
BigFloat that is this * x. |
BigFloat |
multiply(BigFloat x)
Returns the
BigFloat that is this * x. |
BigFloat |
multiply(double x)
Returns the
BigFloat that is this * x. |
BigFloat |
multiply(int x)
Returns the
BigFloat that is this * x. |
BigFloat |
multiply(long x)
Returns the
BigFloat that is this * x. |
static BigFloat |
negate(BigFloat x)
Returns the
BigFloat that is - this. |
BigFloat |
pow(java.math.BigDecimal y)
|
BigFloat |
pow(BigFloat y)
|
static BigFloat |
pow(BigFloat x,
BigFloat y)
Returns the
BigFloat that is pow(x, y). |
BigFloat |
pow(double y)
|
BigFloat |
pow(int y)
|
BigFloat |
pow(long y)
|
BigFloat |
remainder(java.math.BigDecimal x)
|
BigFloat |
remainder(BigFloat x)
|
BigFloat |
remainder(double x)
|
BigFloat |
remainder(int x)
|
BigFloat |
remainder(long x)
|
BigFloat |
root(java.math.BigDecimal y)
|
BigFloat |
root(BigFloat y)
|
static BigFloat |
root(BigFloat x,
BigFloat y)
Returns the
BigFloat that is root(x, y). |
BigFloat |
root(double y)
|
BigFloat |
root(int y)
|
BigFloat |
root(long y)
|
int |
signum()
Returns the signum function of this
BigFloat. |
static BigFloat |
sin(BigFloat x)
Returns the
BigFloat that is sin(x). |
static BigFloat |
sinh(BigFloat x)
Returns the
BigFloat that is sinh(x). |
static BigFloat |
sqrt(BigFloat x)
Returns the
BigFloat that is sqrt(x). |
BigFloat |
subtract(java.math.BigDecimal x)
Returns the
BigFloat that is this - x. |
BigFloat |
subtract(BigFloat x)
Returns the
BigFloat that is this - x. |
BigFloat |
subtract(double x)
Returns the
BigFloat that is this - x. |
BigFloat |
subtract(int x)
Returns the
BigFloat that is this - x. |
BigFloat |
subtract(long x)
Returns the
BigFloat that is this - x. |
static BigFloat |
tan(BigFloat x)
Returns the
BigFloat that is tan(x). |
static BigFloat |
tanh(BigFloat x)
Returns the
BigFloat that is tanh(x). |
java.math.BigDecimal |
toBigDecimal()
Returns
this value as a BigDecimal value. |
double |
toDouble()
Returns
this value as a double value. |
int |
toInt()
Returns
this value as a int value. |
long |
toLong()
Returns
this value as a long value. |
java.lang.String |
toString() |
public BigFloat add(BigFloat x)
BigFloat that is this + x.
If the two values do not have the same BigFloat.Context, the result will contain the BigFloat.Context with the larger precision.
x - the value to addBigFloatBigDecimal.add(BigDecimal, MathContext)public BigFloat add(java.math.BigDecimal x)
BigFloat that is this + x.x - the value to addBigFloatBigDecimal.add(BigDecimal, MathContext)public BigFloat add(int x)
BigFloat that is this + x.x - the value to addBigFloatBigDecimal.add(BigDecimal, MathContext)public BigFloat add(long x)
BigFloat that is this + x.x - the value to addBigFloatBigDecimal.add(BigDecimal, MathContext)public BigFloat add(double x)
BigFloat that is this + x.x - the value to addBigFloatBigDecimal.add(BigDecimal, MathContext)public BigFloat subtract(BigFloat x)
BigFloat that is this - x.
If the two values do not have the same BigFloat.Context, the result will contain the BigFloat.Context with the larger precision.
x - the value to subtractBigFloatBigDecimal.subtract(BigDecimal, MathContext)public BigFloat subtract(java.math.BigDecimal x)
BigFloat that is this - x.x - the value to subtractBigFloatBigDecimal.subtract(BigDecimal, MathContext)public BigFloat subtract(int x)
BigFloat that is this - x.x - the value to subtractBigFloatBigDecimal.subtract(BigDecimal, MathContext)public BigFloat subtract(long x)
BigFloat that is this - x.x - the value to subtractBigFloatBigDecimal.subtract(BigDecimal, MathContext)public BigFloat subtract(double x)
BigFloat that is this - x.x - the value to subtractBigFloatBigDecimal.subtract(BigDecimal, MathContext)public BigFloat multiply(BigFloat x)
BigFloat that is this * x.
If the two values do not have the same BigFloat.Context, the result will contain the BigFloat.Context with the larger precision.
x - the value to multiplyBigFloatBigDecimal.multiply(BigDecimal, MathContext)public BigFloat multiply(java.math.BigDecimal x)
BigFloat that is this * x.x - the value to multiplyBigFloatBigDecimal.multiply(BigDecimal, MathContext)public BigFloat multiply(int x)
BigFloat that is this * x.x - the value to multiplyBigFloatBigDecimal.multiply(BigDecimal, MathContext)public BigFloat multiply(long x)
BigFloat that is this * x.x - the value to multiplyBigFloatBigDecimal.multiply(BigDecimal, MathContext)public BigFloat multiply(double x)
BigFloat that is this * x.x - the value to multiplyBigFloatBigDecimal.multiply(BigDecimal, MathContext)public BigFloat divide(BigFloat x)
BigFloat that is this / x.
If the two values do not have the same BigFloat.Context, the result will contain the BigFloat.Context with the larger precision.
x - the value to divide withBigFloatBigDecimal.divide(BigDecimal, MathContext)public BigFloat divide(java.math.BigDecimal x)
BigFloat that is this / x.x - the value to divide withBigFloatBigDecimal.divide(BigDecimal, MathContext)public BigFloat divide(int x)
BigFloat that is this / x.x - the value to divide withBigFloatBigDecimal.divide(BigDecimal, MathContext)public BigFloat divide(long x)
BigFloat that is this / x.x - the value to divide withBigFloatBigDecimal.divide(BigDecimal, MathContext)public BigFloat divide(double x)
BigFloat that is this / x.x - the value to divide withBigFloatBigDecimal.divide(BigDecimal, MathContext)public BigFloat remainder(BigFloat x)
BigFloat that is the remainder when dividing this by x.
If the two values do not have the same BigFloat.Context, the result will contain the BigFloat.Context with the larger precision.
x - the value to divide withBigFloatBigDecimal.remainder(BigDecimal, MathContext)public BigFloat remainder(java.math.BigDecimal x)
x - the value to divide withBigFloatBigDecimal.remainder(BigDecimal, MathContext)public BigFloat remainder(int x)
x - the value to divide withBigFloatBigDecimal.remainder(BigDecimal, MathContext)public BigFloat remainder(long x)
x - the value to divide withBigFloatBigDecimal.remainder(BigDecimal, MathContext)public BigFloat remainder(double x)
x - the value to divide withBigFloatBigDecimal.remainder(BigDecimal, MathContext)public BigFloat pow(BigFloat y)
BigFloat that is this to the power of y.
If the two values do not have the same BigFloat.Context, the result will contain the BigFloat.Context with the larger precision.
y - the value of the powerBigFloatBigDecimalMath.pow(BigDecimal, BigDecimal, MathContext)public BigFloat pow(java.math.BigDecimal y)
y - the value of the powerBigFloatBigDecimalMath.pow(BigDecimal, BigDecimal, MathContext)public BigFloat pow(int y)
y - the value of the powerBigFloatBigDecimalMath.pow(BigDecimal, BigDecimal, MathContext)public BigFloat pow(long y)
y - the value of the powerBigFloatBigDecimalMath.pow(BigDecimal, BigDecimal, MathContext)public BigFloat pow(double y)
y - the value of the powerBigFloatBigDecimalMath.pow(BigDecimal, BigDecimal, MathContext)public BigFloat root(BigFloat y)
BigFloat that is the yth root of this.
If the two values do not have the same BigFloat.Context, the result will contain the BigFloat.Context with the larger precision.
y - the value of the rootBigFloatBigDecimalMath.root(BigDecimal, BigDecimal, MathContext)public BigFloat root(java.math.BigDecimal y)
y - the value of the rootBigFloatBigDecimalMath.root(BigDecimal, BigDecimal, MathContext)public BigFloat root(int y)
y - the value of the rootBigFloatBigDecimalMath.root(BigDecimal, BigDecimal, MathContext)public BigFloat root(long y)
y - the value of the rootBigFloatBigDecimalMath.root(BigDecimal, BigDecimal, MathContext)public BigFloat root(double y)
y - the value of the rootBigFloatBigDecimalMath.root(BigDecimal, BigDecimal, MathContext)public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int signum()
BigFloat.BigDecimal is negative, zero, or positive.public boolean isNegative()
BigFloat is negative.true if negative, false if 0 or positivepublic boolean isZero()
BigFloat is 0.true if 0, false if negative or positivepublic boolean isPositive()
BigFloat is positive.true if positive, false if 0 or negativepublic int compareTo(BigFloat other)
compareTo in interface java.lang.Comparable<BigFloat>public boolean isEqual(BigFloat other)
this value is mathematically equal to the other value.other - the other BigFloat to compare withtrue if both values are mathematically equal (equivalent to this.compareTo(other) == 0compareTo(BigFloat)public boolean isLessThan(BigFloat other)
this value is mathematically less than to the other value.other - the other BigFloat to compare withtrue this value is mathematically less than to the other value (equivalent to this.compareTo(other) < 0compareTo(BigFloat)public boolean isGreaterThan(BigFloat other)
this value is mathematically greater than to the other value.other - the other BigFloat to compare withtrue this value is mathematically greater than to the other value (equivalent to this.compareTo(other) > 0compareTo(BigFloat)public boolean isLessThanOrEqual(BigFloat other)
this value is mathematically less than or equal to the other value.other - the other BigFloat to compare withtrue this value is mathematically less than or equal to the other value (equivalent to this.compareTo(other) <= 0compareTo(BigFloat),
isLessThan(BigFloat),
isEqual(BigFloat)public boolean isGreaterThanOrEqual(BigFloat other)
this value is mathematically greater than or equal to the other value.other - the other BigFloat to compare withtrue this value is mathematically greater than or equal to the other value (equivalent to this.compareTo(other) >= 0compareTo(BigFloat),
isGreaterThan(BigFloat),
isEqual(BigFloat)public boolean isIntValue()
this value can be represented as int.true if the value can be represented as int valueBigDecimalMath.isIntValue(BigDecimal)public boolean isDoubleValue()
this specified BigDecimal value can be represented as double.true if the value can be represented as double valueBigDecimalMath.isDoubleValue(BigDecimal)public BigFloat getMantissa()
this value written as mantissa * 10exponent.
The mantissa is defined as having exactly 1 digit before the decimal point.
getExponent(),
BigDecimalMath.mantissa(BigDecimal)public BigFloat getExponent()
this value written as mantissa * 10exponent.
The mantissa is defined as having exactly 1 digit before the decimal point.
getMantissa(),
BigDecimalMath.exponent(BigDecimal)public BigFloat getIntegralPart()
this value (left of the decimal point).getFractionalPart(),
BigDecimalMath.fractionalPart(BigDecimal)public BigFloat getFractionalPart()
this value (right of the decimal point).getIntegralPart(),
BigDecimalMath.fractionalPart(BigDecimal)public BigFloat.Context getContext()
BigFloat.Context of this value.BigFloat.Contextpublic java.math.BigDecimal toBigDecimal()
this value as a BigDecimal value.BigDecimal valuepublic double toDouble()
this value as a double value.double valueBigDecimal.doubleValue()public long toLong()
this value as a long value.long valueBigDecimal.longValue()public int toInt()
this value as a int value.int valueBigDecimal.intValue()public java.lang.String toString()
toString in class java.lang.Objectpublic static BigFloat.Context context(int precision)
BigFloat.Context with the specified precision and RoundingMode.HALF_UP rounding.precision - the precisionBigFloat.Contextpublic static BigFloat.Context context(java.math.MathContext mathContext)
BigFloat.Context with the specified MathContext.mathContext - the MathContextBigFloat.Contextpublic static BigFloat negate(BigFloat x)
BigFloat that is - this.x - the value to negateBigFloatBigDecimal.negate(MathContext)public static BigFloat abs(BigFloat x)
BigFloat that is the abs(this) (absolute value).x - the value to make absoluteBigFloatBigDecimal.abs(MathContext)public static BigFloat max(BigFloat value1, BigFloat value2)
BigFloat values.public static BigFloat max(BigFloat value1, BigFloat... values)
BigFloat values.public static BigFloat min(BigFloat value1, BigFloat value2)
BigFloat values.public static BigFloat min(BigFloat value1, BigFloat... values)
BigFloat values.public static BigFloat log(BigFloat x)
BigFloat that is log(x).x - the valueBigFloatBigDecimalMath.log(BigDecimal, MathContext)public static BigFloat log2(BigFloat x)
BigFloat that is log2(x).x - the valueBigFloatBigDecimalMath.log2(BigDecimal, MathContext)public static BigFloat log10(BigFloat x)
BigFloat that is log10(x).x - the valueBigFloatBigDecimalMath.log10(BigDecimal, MathContext)public static BigFloat exp(BigFloat x)
BigFloat that is exp(x).x - the valueBigFloatBigDecimalMath.exp(BigDecimal, MathContext)public static BigFloat sqrt(BigFloat x)
BigFloat that is sqrt(x).x - the valueBigFloatBigDecimalMath.sqrt(BigDecimal, MathContext)public static BigFloat pow(BigFloat x, BigFloat y)
BigFloat that is pow(x, y).
If the two values do not have the same BigFloat.Context, the result will contain the BigFloat.Context with the larger precision.
x - the BigFloat value to take to the powery - the BigFloat value to serve as exponentBigFloatBigDecimalMath.pow(BigDecimal, BigDecimal, MathContext)public static BigFloat root(BigFloat x, BigFloat y)
BigFloat that is root(x, y).
If the two values do not have the same BigFloat.Context, the result will contain the BigFloat.Context with the larger precision.
x - the BigFloat value to calculate the n'th rooty - the BigFloat defining the rootBigFloatBigDecimalMath.pow(BigDecimal, BigDecimal, MathContext)public static BigFloat sin(BigFloat x)
BigFloat that is sin(x).x - the valueBigFloatBigDecimalMath.sin(BigDecimal, MathContext)public static BigFloat cos(BigFloat x)
BigFloat that is cos(x).x - the valueBigFloatBigDecimalMath.cos(BigDecimal, MathContext)public static BigFloat tan(BigFloat x)
BigFloat that is tan(x).x - the valueBigFloatBigDecimalMath.tan(BigDecimal, MathContext)public static BigFloat cot(BigFloat x)
BigFloat that is cot(x).x - the valueBigFloatBigDecimalMath.cot(BigDecimal, MathContext)public static BigFloat asin(BigFloat x)
BigFloat that is asin(x).x - the valueBigFloatBigDecimalMath.asin(BigDecimal, MathContext)public static BigFloat acos(BigFloat x)
BigFloat that is acos(x).x - the valueBigFloatBigDecimalMath.acos(BigDecimal, MathContext)public static BigFloat atan(BigFloat x)
BigFloat that is atan(x).x - the valueBigFloatBigDecimalMath.atan(BigDecimal, MathContext)public static BigFloat acot(BigFloat x)
BigFloat that is acot(x).x - the valueBigFloatBigDecimalMath.acot(BigDecimal, MathContext)public static BigFloat sinh(BigFloat x)
BigFloat that is sinh(x).x - the valueBigFloatBigDecimalMath.sinh(BigDecimal, MathContext)public static BigFloat cosh(BigFloat x)
BigFloat that is cosh(x).x - the valueBigFloatBigDecimalMath.cosh(BigDecimal, MathContext)public static BigFloat tanh(BigFloat x)
BigFloat that is tanh(x).x - the valueBigFloatBigDecimalMath.tanh(BigDecimal, MathContext)public static BigFloat coth(BigFloat x)
BigFloat that is coth(x).x - the valueBigFloatBigDecimalMath.coth(BigDecimal, MathContext)public static BigFloat asinh(BigFloat x)
BigFloat that is asinh(x).x - the valueBigFloatBigDecimalMath.asinh(BigDecimal, MathContext)public static BigFloat acosh(BigFloat x)
BigFloat that is acosh(x).x - the valueBigFloatBigDecimalMath.acosh(BigDecimal, MathContext)public static BigFloat atanh(BigFloat x)
BigFloat that is atanh(x).x - the valueBigFloatBigDecimalMath.atanh(BigDecimal, MathContext)public static BigFloat acoth(BigFloat x)
BigFloat that is acoth(x).x - the valueBigFloatBigDecimalMath.acoth(BigDecimal, MathContext)