public class FloatApfloatImpl extends FloatBaseMath implements ApfloatImpl
float data element type.
The associated DataStorage is assumed to be immutable also.
This way performance can be improved by sharing the data storage between
different ApfloatImpl's and by only varying the
ApfloatImpl specific fields, like sign, precision and exponent.
This implementation doesn't necessarily store any extra digits for added precision, so the last digit of any operation may be inaccurate.
| Constructor and Description |
|---|
FloatApfloatImpl(double value,
long precision,
int radix)
Create a new
FloatApfloatImpl instance from a double. |
FloatApfloatImpl(long value,
long precision,
int radix)
Create a new
FloatApfloatImpl instance from a long. |
FloatApfloatImpl(PushbackReader in,
long precision,
int radix,
boolean isInteger)
Create a new
FloatApfloatImpl instance reading from a stream. |
FloatApfloatImpl(String value,
long precision,
int radix,
boolean isInteger)
Create a new
FloatApfloatImpl instance from a String. |
| Modifier and Type | Method and Description |
|---|---|
ApfloatImpl |
absCeil()
Returns this
ApfloatImpl rounded away from zero. |
ApfloatImpl |
absFloor()
Returns this
ApfloatImpl rounded towards zero. |
ApfloatImpl |
addOrSubtract(ApfloatImpl x,
boolean subtract)
Add or subtract an
ApfloatImpl to this object. |
int |
compareTo(ApfloatImpl x)
Compare this
ApfloatImpl and another number. |
ApfloatImpl |
divideShort(ApfloatImpl x)
Divide this
ApfloatImpl by an ApfloatImpl that is "short". |
double |
doubleValue()
Returns the value of the this number as a
double. |
long |
equalDigits(ApfloatImpl x)
The number of equal digits in this
ApfloatImpl and another number. |
boolean |
equals(Object obj)
Compares this object to the specified object.
|
ApfloatImpl |
frac()
Returns the fractional part of this
ApfloatImpl. |
int |
hashCode()
Returns the hash code for this
ApfloatImpl. |
boolean |
isOne()
Tests if this number is equal to 1.
|
boolean |
isShort()
Returns if this
ApfloatImpl is "short". |
long |
longValue()
Returns the value of the this number as a
long. |
ApfloatImpl |
multiply(ApfloatImpl x)
Multiply this object by an
ApfloatImpl. |
ApfloatImpl |
negate()
Returns this
ApfloatImpl negated. |
long |
precision()
Returns the precision of this
ApfloatImpl. |
ApfloatImpl |
precision(long precision)
Returns this
ApfloatImpl with the specified precision. |
int |
radix()
Returns the radix of this
ApfloatImpl. |
long |
scale()
Returns the scale of this
ApfloatImpl. |
int |
signum()
Returns the signum of this
ApfloatImpl. |
long |
size()
Returns the size of the mantissa of this
ApfloatImpl. |
String |
toString(boolean pretty)
Convert this
ApfloatImpl to String. |
void |
writeTo(Writer out,
boolean pretty)
Print this
ApfloatImpl to a stream. |
baseAdd, baseDivide, baseMultiplyAdd, baseSubtractpublic FloatApfloatImpl(String value, long precision, int radix, boolean isInteger) throws NumberFormatException, ApfloatRuntimeException
FloatApfloatImpl instance from a String.value - The string to be parsed to a number.precision - The precision of the number (in digits of the radix).radix - The radix in which the number is created.isInteger - Specifies if the number to be parsed from the string is to be treated as an integer or not.NumberFormatException - If the number is not valid.ApfloatRuntimeExceptionpublic FloatApfloatImpl(long value,
long precision,
int radix)
throws NumberFormatException,
ApfloatRuntimeException
FloatApfloatImpl instance from a long.value - The value of the number.precision - The precision of the number (in digits of the radix).radix - The radix in which the number is created.NumberFormatException - If the number is not valid.ApfloatRuntimeExceptionpublic FloatApfloatImpl(double value,
long precision,
int radix)
throws NumberFormatException,
ApfloatRuntimeException
FloatApfloatImpl instance from a double.value - The value of the number.precision - The precision of the number (in digits of the radix).radix - The radix in which the number is created.NumberFormatException - If the number is not valid.ApfloatRuntimeExceptionpublic FloatApfloatImpl(PushbackReader in, long precision, int radix, boolean isInteger) throws IOException, NumberFormatException, ApfloatRuntimeException
FloatApfloatImpl instance reading from a stream.
Implementation note: this constructor calls the in stream's
single-character read() method. If the underlying stream doesn't
explicitly implement this method in some efficient way, but simply inherits it
from the Reader base class, performance will suffer as the default
Reader method creates a new char[1] on every call to
read().
in - The stream to read from.precision - The precision of the number (in digits of the radix).radix - The radix in which the number is created.isInteger - Specifies if the number to be parsed from the stream is to be treated as an integer or not.IOException - If an I/O error occurs accessing the stream.NumberFormatException - If the number is not valid.ApfloatRuntimeExceptionpublic ApfloatImpl addOrSubtract(ApfloatImpl x, boolean subtract) throws ApfloatRuntimeException
ApfloatImplApfloatImpl to this object.addOrSubtract in interface ApfloatImplx - The number to be added or subtracted to this ApfloatImpl.subtract - true if the numbers are to be subtracted, false if added.this + x or this - x depending on the subtract argument.ApfloatRuntimeExceptionpublic ApfloatImpl multiply(ApfloatImpl x) throws ApfloatRuntimeException
ApfloatImplApfloatImpl.multiply in interface ApfloatImplx - The number to be multiplied by this ApfloatImpl.this * x.ApfloatRuntimeExceptionpublic boolean isShort()
throws ApfloatRuntimeException
ApfloatImplApfloatImpl is "short". Typically ApfloatImpl
is "short" if its mantissa fits in one machine word. If the apfloat is "short",
some algorithms can be performed faster.The return value of this method is highly implementation dependent.
isShort in interface ApfloatImpltrue if the ApfloatImpl is "short", false if not.ApfloatRuntimeExceptionApfloat.isShort()public ApfloatImpl divideShort(ApfloatImpl x) throws ApfloatRuntimeException
ApfloatImplApfloatImpl by an ApfloatImpl that is "short".divideShort in interface ApfloatImplx - The number by which this ApfloatImpl is to be divided.this / x.ApfloatRuntimeExceptionpublic ApfloatImpl absFloor() throws ApfloatRuntimeException
ApfloatImplApfloatImpl rounded towards zero.absFloor in interface ApfloatImplApfloatImpl rounded towards zero.ApfloatRuntimeExceptionpublic ApfloatImpl absCeil() throws ApfloatRuntimeException
ApfloatImplApfloatImpl rounded away from zero.absCeil in interface ApfloatImplApfloatImpl rounded away from zero.ApfloatRuntimeExceptionpublic ApfloatImpl frac() throws ApfloatRuntimeException
ApfloatImplApfloatImpl.frac in interface ApfloatImplApfloatImpl.ApfloatRuntimeExceptionpublic int radix()
ApfloatImplApfloatImpl.radix in interface ApfloatImplApfloatImpl.public long precision()
ApfloatImplApfloatImpl.precision in interface ApfloatImplApfloatImpl.public long size()
throws ApfloatRuntimeException
ApfloatImplApfloatImpl.size in interface ApfloatImplApfloatImpl.ApfloatRuntimeExceptionpublic ApfloatImpl precision(long precision)
ApfloatImplApfloatImpl with the specified precision.precision in interface ApfloatImplprecision - The precision.ApfloatImpl with the specified precision.public long scale()
throws ApfloatRuntimeException
ApfloatImplApfloatImpl.scale in interface ApfloatImplApfloatImpl.ApfloatRuntimeExceptionApfloat.scale()public int signum()
ApfloatImplApfloatImpl.signum in interface ApfloatImplApfloatImpl.Apfloat.signum()public ApfloatImpl negate() throws ApfloatRuntimeException
ApfloatImplApfloatImpl negated.negate in interface ApfloatImpl-this.ApfloatRuntimeExceptionpublic double doubleValue()
ApfloatImpldouble.
If the number is greater than Double.MAX_VALUE,
then Double.POSITIVE_INFINITY is returned.
If the number is less than Double.MIN_VALUE,
then Double.NEGATIVE_INFINITY is returned.
If the number is very small in magnitude, underflow may happen and zero is returned.
doubleValue in interface ApfloatImpldouble.public long longValue()
ApfloatImpllong.
The fractional part is truncated towards zero.
If the number is greater than Long.MAX_VALUE,
then Long.MAX_VALUE is returned.
If the number is less than Long.MIN_VALUE,
then Long.MIN_VALUE is returned.
longValue in interface ApfloatImpllong.public boolean isOne()
throws ApfloatRuntimeException
ApfloatImplisOne in interface ApfloatImpltrue if this number is equal to one, otherwise false.ApfloatRuntimeExceptionpublic long equalDigits(ApfloatImpl x) throws ApfloatRuntimeException
ApfloatImplApfloatImpl and another number.equalDigits in interface ApfloatImplx - The number to compare with.ApfloatImpl and x.ApfloatRuntimeExceptionApfloat.equalDigits(org.apfloat.Apfloat)public int compareTo(ApfloatImpl x) throws ApfloatRuntimeException
ApfloatImplApfloatImpl and another number.compareTo in interface ApfloatImplx - The number to compare with.ApfloatRuntimeExceptionApfloat.compareTo(org.apfloat.Apfloat)public boolean equals(Object obj)
public int hashCode()
ApfloatImplApfloatImpl.hashCode in interface ApfloatImplhashCode in class ObjectApfloatImpl.public String toString(boolean pretty) throws ApfloatRuntimeException
ApfloatImplApfloatImpl to String.toString in interface ApfloatImplpretty - Flag for formatting.ApfloatImpl.ApfloatRuntimeExceptionApfloat.toString(boolean)public void writeTo(Writer out, boolean pretty) throws IOException, ApfloatRuntimeException
ApfloatImplApfloatImpl to a stream.writeTo in interface ApfloatImplout - The stream to write to.pretty - Flag for formatting.IOException - In case of I/O error writing to the stream.ApfloatRuntimeExceptionApfloat.writeTo(Writer,boolean)Copyright © 2024. All rights reserved.