public class LongApfloatImpl extends LongBaseMath implements ApfloatImpl
long
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 |
---|
LongApfloatImpl(double value,
long precision,
int radix)
Create a new
LongApfloatImpl instance from a double . |
LongApfloatImpl(long value,
long precision,
int radix)
Create a new
LongApfloatImpl instance from a long . |
LongApfloatImpl(PushbackReader in,
long precision,
int radix,
boolean isInteger)
Create a new
LongApfloatImpl instance reading from a stream. |
LongApfloatImpl(String value,
long precision,
int radix,
boolean isInteger)
Create a new
LongApfloatImpl 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, baseSubtract
public LongApfloatImpl(String value, long precision, int radix, boolean isInteger) throws NumberFormatException, ApfloatRuntimeException
LongApfloatImpl
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.ApfloatRuntimeException
public LongApfloatImpl(long value, long precision, int radix) throws NumberFormatException, ApfloatRuntimeException
LongApfloatImpl
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.ApfloatRuntimeException
public LongApfloatImpl(double value, long precision, int radix) throws NumberFormatException, ApfloatRuntimeException
LongApfloatImpl
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.ApfloatRuntimeException
public LongApfloatImpl(PushbackReader in, long precision, int radix, boolean isInteger) throws IOException, NumberFormatException, ApfloatRuntimeException
LongApfloatImpl
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.ApfloatRuntimeException
public ApfloatImpl addOrSubtract(ApfloatImpl x, boolean subtract) throws ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
to this object.addOrSubtract
in interface ApfloatImpl
x
- 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.ApfloatRuntimeException
public ApfloatImpl multiply(ApfloatImpl x) throws ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
.multiply
in interface ApfloatImpl
x
- The number to be multiplied by this ApfloatImpl
.this * x
.ApfloatRuntimeException
public boolean isShort() throws ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
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 ApfloatImpl
true
if the ApfloatImpl
is "short", false
if not.ApfloatRuntimeException
Apfloat.isShort()
public ApfloatImpl divideShort(ApfloatImpl x) throws ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
by an ApfloatImpl
that is "short".divideShort
in interface ApfloatImpl
x
- The number by which this ApfloatImpl
is to be divided.this / x
.ApfloatRuntimeException
public ApfloatImpl absFloor() throws ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
rounded towards zero.absFloor
in interface ApfloatImpl
ApfloatImpl
rounded towards zero.ApfloatRuntimeException
public ApfloatImpl absCeil() throws ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
rounded away from zero.absCeil
in interface ApfloatImpl
ApfloatImpl
rounded away from zero.ApfloatRuntimeException
public ApfloatImpl frac() throws ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
.frac
in interface ApfloatImpl
ApfloatImpl
.ApfloatRuntimeException
public int radix()
ApfloatImpl
ApfloatImpl
.radix
in interface ApfloatImpl
ApfloatImpl
.public long precision()
ApfloatImpl
ApfloatImpl
.precision
in interface ApfloatImpl
ApfloatImpl
.public long size() throws ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
.size
in interface ApfloatImpl
ApfloatImpl
.ApfloatRuntimeException
public ApfloatImpl precision(long precision)
ApfloatImpl
ApfloatImpl
with the specified precision.precision
in interface ApfloatImpl
precision
- The precision.ApfloatImpl
with the specified precision.public long scale() throws ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
.scale
in interface ApfloatImpl
ApfloatImpl
.ApfloatRuntimeException
Apfloat.scale()
public int signum()
ApfloatImpl
ApfloatImpl
.signum
in interface ApfloatImpl
ApfloatImpl
.Apfloat.signum()
public ApfloatImpl negate() throws ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
negated.negate
in interface ApfloatImpl
-this
.ApfloatRuntimeException
public double doubleValue()
ApfloatImpl
double
.
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 ApfloatImpl
double
.public long longValue()
ApfloatImpl
long
.
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 ApfloatImpl
long
.public boolean isOne() throws ApfloatRuntimeException
ApfloatImpl
isOne
in interface ApfloatImpl
true
if this number is equal to one, otherwise false
.ApfloatRuntimeException
public long equalDigits(ApfloatImpl x) throws ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
and another number.equalDigits
in interface ApfloatImpl
x
- The number to compare with.ApfloatImpl
and x
.ApfloatRuntimeException
Apfloat.equalDigits(org.apfloat.Apfloat)
public int compareTo(ApfloatImpl x) throws ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
and another number.compareTo
in interface ApfloatImpl
x
- The number to compare with.ApfloatRuntimeException
Apfloat.compareTo(org.apfloat.Apfloat)
public boolean equals(Object obj)
public int hashCode()
ApfloatImpl
ApfloatImpl
.hashCode
in interface ApfloatImpl
hashCode
in class Object
ApfloatImpl
.public String toString(boolean pretty) throws ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
to String
.toString
in interface ApfloatImpl
pretty
- Flag for formatting.ApfloatImpl
.ApfloatRuntimeException
Apfloat.toString(boolean)
public void writeTo(Writer out, boolean pretty) throws IOException, ApfloatRuntimeException
ApfloatImpl
ApfloatImpl
to a stream.writeTo
in interface ApfloatImpl
out
- The stream to write to.pretty
- Flag for formatting.IOException
- In case of I/O error writing to the stream.ApfloatRuntimeException
Apfloat.writeTo(Writer,boolean)
Copyright © 2017. All rights reserved.