public final class FloatingPoint extends Number<FloatingPoint> implements Field<FloatingPoint>
This class represents a floating point number of arbitrary precision.
A floating point number consists of a significand
and a decimal exponent:
(significand · 10exponent).
Unlike Real numbers, no calculation error is performed on
floating point instances but the number of digits used during
calculations can be specified (see setDigits(int)). The
largest the number of digits, the smallest the numeric error.
For example:[code]
FloatingPoint two = FloatingPoint.valueOf(2);
FloatingPoint.setDigits(30); // 30 digits calculations.
System.out.println(two.sqrt());
> 0.141421356237309504880168872420E1
[/code]
Instances of this class are immutable and can be used to find
accurate solutions to linear equations with the Matrix class.
| Modifier and Type | Field and Description |
|---|---|
static FloatingPoint |
NaN
The Not-a-Number instance (unique).
|
static FloatingPoint |
ONE
The floating point instance representing the multiplicative identity.
|
static FloatingPoint |
ZERO
The floating point instance representing the additive identity.
|
| Modifier and Type | Method and Description |
|---|---|
FloatingPoint |
abs()
Returns the absolute value of this floating point number.
|
int |
compareTo(FloatingPoint that)
Compares two floating point number numerically.
|
FloatingPoint |
copy()
Returns a copy of this number
allocated
by the calling thread (possibly on the stack). |
FloatingPoint |
divide(FloatingPoint that)
Returns this floating point number divided by the one specified.
|
double |
doubleValue()
Returns the value of this floating point number as a
double. |
boolean |
equals(Object that)
Compares this floating point number against the specified object.
|
static int |
getDigits()
Returns the
local number of
digits used during calculations (default 20 digits). |
int |
getExponent()
Returns the decimal exponent.
|
LargeInteger |
getSignificand()
Returns the significand value.
|
int |
hashCode()
Returns the hash code for this floating point number.
|
FloatingPoint |
inverse()
Returns the inverse of this floating point number.
|
boolean |
isLargerThan(FloatingPoint that)
Compares the absolute value of two FloatingPoint numbers.
|
boolean |
isNaN()
Indicates if this floating point is Not-a-Number.
|
boolean |
isNegative()
Indicates if this rational number is less than zero.
|
boolean |
isPositive()
Indicates if this floating point number is greater than zero.
|
boolean |
isZero()
Indicates if this floating point number is equal to zero.
|
long |
longValue()
Returns the value of this floating point number as a
long. |
FloatingPoint |
minus(FloatingPoint that)
Returns the difference between this FloatingPoint number and the one
specified.
|
FloatingPoint |
opposite()
Returns the opposite of this floating point number.
|
FloatingPoint |
plus(FloatingPoint that)
Returns the sum of this floating point number with the one specified.
|
LargeInteger |
round()
Returns the closest integer to this floating point number.
|
static void |
setDigits(int digits)
Sets the
local number of digits
to be used during calculations. |
FloatingPoint |
sqrt()
Returns the square root of this floating point number.
|
FloatingPoint |
times(FloatingPoint that)
Returns the product of this floating point number with the one specified.
|
FloatingPoint |
times(long multiplier)
Returns the product of this floating point number with the specified
long multiplier. |
javolution.text.Text |
toText()
Returns the decimal text representation of this number.
|
static FloatingPoint |
valueOf(CharSequence chars)
Returns the floating point number for the specified character sequence.
|
static FloatingPoint |
valueOf(double doubleValue)
Returns the floating point number for the specified
double
value (convenience method). |
static FloatingPoint |
valueOf(LargeInteger significand,
int exponent)
Returns the floating point number for the specified
LargeInteger significand and power of two exponent. |
static FloatingPoint |
valueOf(long longValue)
Returns the floating point number for the specified
long
value (convenience method). |
static FloatingPoint |
valueOf(long significand,
int exponent)
Returns the floating point number for the specified
long
significand and power of two exponent (convenience method). |
byteValue, floatValue, intValue, isGreaterThan, isLessThan, pow, shortValue, toStringpublic static final FloatingPoint ZERO
public static final FloatingPoint ONE
public static final FloatingPoint NaN
public static FloatingPoint valueOf(LargeInteger significand, int exponent)
LargeInteger significand and power of two exponent.significand - the significand value.exponent - the power of two exponent.(significand · 2exponentpublic static FloatingPoint valueOf(long significand, int exponent)
long
significand and power of two exponent (convenience method).significand - the significand value.exponent - the power of two exponent.(significand · 2exponentpublic static FloatingPoint valueOf(long longValue)
long
value (convenience method).longValue - the long value.FloatingPoint.valueOf(longValue, 0)public static FloatingPoint valueOf(double doubleValue)
double
value (convenience method).doubleValue - the double value.FloatingPoint.valueOf(longValue, 0)public static FloatingPoint valueOf(CharSequence chars)
chars - the character sequence.public static int getDigits()
local number of
digits used during calculations (default 20 digits).public static void setDigits(int digits)
local number of digits
to be used during calculations.digits - the number of digits.IllegalArgumentException - if digits <= 0public LargeInteger getSignificand()
public int getExponent()
public LargeInteger round()
public FloatingPoint opposite()
opposite in interface GroupAdditive<FloatingPoint>-this.public FloatingPoint plus(FloatingPoint that)
plus in interface GroupAdditive<FloatingPoint>that - the floating point number to be added.this + that.public FloatingPoint minus(FloatingPoint that)
minus in class Number<FloatingPoint>that - the floating point number to be subtracted.this - that.public FloatingPoint times(long multiplier)
long multiplier.multiplier - the long multiplier.this · multiplier.public FloatingPoint times(FloatingPoint that)
times in interface GroupMultiplicative<FloatingPoint>times in interface Ring<FloatingPoint>that - the floating point number multiplier.this · that.public FloatingPoint inverse()
inverse in interface GroupMultiplicative<FloatingPoint>1 / this.ArithmeticException - if dividend.isZero()public FloatingPoint divide(FloatingPoint that)
that - the FloatingPoint number divisor.this / that.ArithmeticException - if that.equals(ZERO)public FloatingPoint abs()
|this|.public FloatingPoint sqrt()
public boolean isZero()
this == 0public boolean isPositive()
this > 0public boolean isNegative()
this < 0public boolean isNaN()
true if this number has unbounded value;
false otherwise.public boolean isLargerThan(FloatingPoint that)
isLargerThan in class Number<FloatingPoint>that - the FloatingPoint number to be compared with.|this| > |that|public javolution.text.Text toText()
toText in interface javolution.lang.RealtimetoText in class Number<FloatingPoint>public boolean equals(Object that)
equals in class Number<FloatingPoint>that - the object to compare with.true if the objects are the same;
false otherwise.public int hashCode()
hashCode in class Number<FloatingPoint>public long longValue()
long.longValue in class Number<FloatingPoint>long.public double doubleValue()
double.doubleValue in class Number<FloatingPoint>double.public int compareTo(FloatingPoint that)
compareTo in interface Comparable<FloatingPoint>compareTo in class Number<FloatingPoint>that - the floating point number to compare with.that.public FloatingPoint copy()
Numberallocated
by the calling thread (possibly on the stack).copy in interface javolution.lang.ValueTypecopy in class Number<FloatingPoint>