Class IntApfloatImpl
- All Implemented Interfaces:
Serializable
,ApfloatImpl
int
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.
- Version:
- 1.11.0
- Author:
- Mikko Tommila
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionIntApfloatImpl
(double value, long precision, int radix) Create a newIntApfloatImpl
instance from adouble
.IntApfloatImpl
(long value, long precision, int radix) Create a newIntApfloatImpl
instance from along
.IntApfloatImpl
(PushbackReader in, long precision, int radix, boolean isInteger) Create a newIntApfloatImpl
instance reading from a stream.IntApfloatImpl
(String value, long precision, int radix, boolean isInteger) Create a newIntApfloatImpl
instance from a String. -
Method Summary
Modifier and TypeMethodDescriptionabsCeil()
Returns thisApfloatImpl
rounded away from zero.absFloor()
Returns thisApfloatImpl
rounded towards zero.addOrSubtract
(ApfloatImpl x, boolean subtract) Add or subtract anApfloatImpl
to this object.int
Compare thisApfloatImpl
and another number.Divide thisApfloatImpl
by anApfloatImpl
that is "short".double
Returns the value of the this number as adouble
.long
The number of equal digits in thisApfloatImpl
and another number.boolean
Compares this object to the specified object.frac()
Returns the fractional part of thisApfloatImpl
.int
hashCode()
Returns the hash code for thisApfloatImpl
.boolean
isOne()
Tests if this number is equal to 1.boolean
isShort()
Returns if thisApfloatImpl
is "short".long
Returns the value of the this number as along
.Multiply this object by anApfloatImpl
.negate()
Returns thisApfloatImpl
negated.long
Returns the precision of thisApfloatImpl
.precision
(long precision) Returns thisApfloatImpl
with the specified precision.int
radix()
Returns the radix of thisApfloatImpl
.long
scale()
Returns the scale of thisApfloatImpl
.int
signum()
Returns the signum of thisApfloatImpl
.long
size()
Returns the size of the mantissa of thisApfloatImpl
.toString
(boolean pretty) Convert thisApfloatImpl
toString
.void
Print thisApfloatImpl
to a stream.Methods inherited from class org.apfloat.internal.IntBaseMath
baseAdd, baseDivide, baseMultiplyAdd, baseSubtract
-
Constructor Details
-
IntApfloatImpl
public IntApfloatImpl(String value, long precision, int radix, boolean isInteger) throws NumberFormatException, ApfloatRuntimeException Create a newIntApfloatImpl
instance from a String.- Parameters:
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.- Throws:
NumberFormatException
- If the number is not valid.ApfloatRuntimeException
-
IntApfloatImpl
public IntApfloatImpl(long value, long precision, int radix) throws NumberFormatException, ApfloatRuntimeException Create a newIntApfloatImpl
instance from along
.- Parameters:
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.- Throws:
NumberFormatException
- If the number is not valid.ApfloatRuntimeException
-
IntApfloatImpl
public IntApfloatImpl(double value, long precision, int radix) throws NumberFormatException, ApfloatRuntimeException Create a newIntApfloatImpl
instance from adouble
.- Parameters:
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.- Throws:
NumberFormatException
- If the number is not valid.ApfloatRuntimeException
-
IntApfloatImpl
public IntApfloatImpl(PushbackReader in, long precision, int radix, boolean isInteger) throws IOException, NumberFormatException, ApfloatRuntimeException Create a newIntApfloatImpl
instance reading from a stream.Implementation note: this constructor calls the
in
stream's single-characterread()
method. If the underlying stream doesn't explicitly implement this method in some efficient way, but simply inherits it from theReader
base class, performance will suffer as the defaultReader
method creates anew char[1]
on every call toread()
.- Parameters:
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.- Throws:
IOException
- If an I/O error occurs accessing the stream.NumberFormatException
- If the number is not valid.ApfloatRuntimeException
-
-
Method Details
-
addOrSubtract
Description copied from interface:ApfloatImpl
Add or subtract anApfloatImpl
to this object.- Specified by:
addOrSubtract
in interfaceApfloatImpl
- Parameters:
x
- The number to be added or subtracted to thisApfloatImpl
.subtract
-true
if the numbers are to be subtracted,false
if added.- Returns:
this + x
orthis - x
depending on thesubtract
argument.- Throws:
ApfloatRuntimeException
-
multiply
Description copied from interface:ApfloatImpl
Multiply this object by anApfloatImpl
.- Specified by:
multiply
in interfaceApfloatImpl
- Parameters:
x
- The number to be multiplied by thisApfloatImpl
.- Returns:
this * x
.- Throws:
ApfloatRuntimeException
-
isShort
Description copied from interface:ApfloatImpl
Returns if thisApfloatImpl
is "short". TypicallyApfloatImpl
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.
- Specified by:
isShort
in interfaceApfloatImpl
- Returns:
true
if theApfloatImpl
is "short",false
if not.- Throws:
ApfloatRuntimeException
- See Also:
-
divideShort
Description copied from interface:ApfloatImpl
Divide thisApfloatImpl
by anApfloatImpl
that is "short".- Specified by:
divideShort
in interfaceApfloatImpl
- Parameters:
x
- The number by which thisApfloatImpl
is to be divided.- Returns:
this / x
.- Throws:
ApfloatRuntimeException
-
absFloor
Description copied from interface:ApfloatImpl
Returns thisApfloatImpl
rounded towards zero.- Specified by:
absFloor
in interfaceApfloatImpl
- Returns:
- This
ApfloatImpl
rounded towards zero. - Throws:
ApfloatRuntimeException
-
absCeil
Description copied from interface:ApfloatImpl
Returns thisApfloatImpl
rounded away from zero.- Specified by:
absCeil
in interfaceApfloatImpl
- Returns:
- This
ApfloatImpl
rounded away from zero. - Throws:
ApfloatRuntimeException
-
frac
Description copied from interface:ApfloatImpl
Returns the fractional part of thisApfloatImpl
.- Specified by:
frac
in interfaceApfloatImpl
- Returns:
- The fractional part of this
ApfloatImpl
. - Throws:
ApfloatRuntimeException
-
radix
public int radix()Description copied from interface:ApfloatImpl
Returns the radix of thisApfloatImpl
.- Specified by:
radix
in interfaceApfloatImpl
- Returns:
- The radix of this
ApfloatImpl
.
-
precision
public long precision()Description copied from interface:ApfloatImpl
Returns the precision of thisApfloatImpl
.- Specified by:
precision
in interfaceApfloatImpl
- Returns:
- The precision of this
ApfloatImpl
.
-
size
Description copied from interface:ApfloatImpl
Returns the size of the mantissa of thisApfloatImpl
.- Specified by:
size
in interfaceApfloatImpl
- Returns:
- The size of the mantissa of this
ApfloatImpl
. - Throws:
ApfloatRuntimeException
-
precision
Description copied from interface:ApfloatImpl
Returns thisApfloatImpl
with the specified precision.- Specified by:
precision
in interfaceApfloatImpl
- Parameters:
precision
- The precision.- Returns:
- This
ApfloatImpl
with the specified precision.
-
scale
Description copied from interface:ApfloatImpl
Returns the scale of thisApfloatImpl
.- Specified by:
scale
in interfaceApfloatImpl
- Returns:
- The scale of this
ApfloatImpl
. - Throws:
ApfloatRuntimeException
- See Also:
-
signum
public int signum()Description copied from interface:ApfloatImpl
Returns the signum of thisApfloatImpl
.- Specified by:
signum
in interfaceApfloatImpl
- Returns:
- The signum of this
ApfloatImpl
. - See Also:
-
negate
Description copied from interface:ApfloatImpl
Returns thisApfloatImpl
negated.- Specified by:
negate
in interfaceApfloatImpl
- Returns:
-this
.- Throws:
ApfloatRuntimeException
-
doubleValue
public double doubleValue()Description copied from interface:ApfloatImpl
Returns the value of the this number as adouble
. If the number is greater thanDouble.MAX_VALUE
, thenDouble.POSITIVE_INFINITY
is returned.If the number is less than
Double.MIN_VALUE
, thenDouble.NEGATIVE_INFINITY
is returned.If the number is very small in magnitude, underflow may happen and zero is returned.
- Specified by:
doubleValue
in interfaceApfloatImpl
- Returns:
- The numeric value represented by this object after conversion to type
double
.
-
longValue
public long longValue()Description copied from interface:ApfloatImpl
Returns the value of the this number as along
. The fractional part is truncated towards zero.If the number is greater than
Long.MAX_VALUE
, thenLong.MAX_VALUE
is returned.If the number is less than
Long.MIN_VALUE
, thenLong.MIN_VALUE
is returned.- Specified by:
longValue
in interfaceApfloatImpl
- Returns:
- The numeric value represented by this object after conversion to type
long
.
-
isOne
Description copied from interface:ApfloatImpl
Tests if this number is equal to 1.- Specified by:
isOne
in interfaceApfloatImpl
- Returns:
true
if this number is equal to one, otherwisefalse
.- Throws:
ApfloatRuntimeException
-
equalDigits
Description copied from interface:ApfloatImpl
The number of equal digits in thisApfloatImpl
and another number.- Specified by:
equalDigits
in interfaceApfloatImpl
- Parameters:
x
- The number to compare with.- Returns:
- The number of equal digits in this
ApfloatImpl
andx
. - Throws:
ApfloatRuntimeException
- See Also:
-
compareTo
Description copied from interface:ApfloatImpl
Compare thisApfloatImpl
and another number.- Specified by:
compareTo
in interfaceApfloatImpl
- Parameters:
x
- The number to compare with.- Returns:
- Zero, less than zero or greater than zero depending on the result of the comparison.
- Throws:
ApfloatRuntimeException
- See Also:
-
equals
-
hashCode
public int hashCode()Description copied from interface:ApfloatImpl
Returns the hash code for thisApfloatImpl
.- Specified by:
hashCode
in interfaceApfloatImpl
- Overrides:
hashCode
in classObject
- Returns:
- The hash code for this
ApfloatImpl
.
-
toString
Description copied from interface:ApfloatImpl
Convert thisApfloatImpl
toString
.- Specified by:
toString
in interfaceApfloatImpl
- Parameters:
pretty
- Flag for formatting.- Returns:
- String representation of this
ApfloatImpl
. - Throws:
ApfloatRuntimeException
- See Also:
-
writeTo
Description copied from interface:ApfloatImpl
Print thisApfloatImpl
to a stream.- Specified by:
writeTo
in interfaceApfloatImpl
- Parameters:
out
- The stream to write to.pretty
- Flag for formatting.- Throws:
IOException
- In case of I/O error writing to the stream.ApfloatRuntimeException
- See Also:
-