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
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DataStorage
private long
private int
private int
private int
private long
private static final int
private static final int
private long
private int
private static final long
private int
private long
private static final int
private static final DataStorage.Iterator
-
Constructor Summary
ConstructorsModifierConstructorDescriptionIntApfloatImpl
(double value, long precision, int radix) Create a newIntApfloatImpl
instance from adouble
.private
IntApfloatImpl
(int sign, long precision, long exponent, DataStorage dataStorage, int radix) 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.private static int
checkRadix
(int radix) private int
int
Compare thisApfloatImpl
and another number.private static DataStorage
createDataStorage
(long size) 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.private long
findMismatch
(DataStorage.Iterator thisIterator, DataStorage.Iterator thatIterator, long size) private void
formatWord
(char[] buffer, int word) frac()
Returns the fractional part of thisApfloatImpl
.private long
private long
getBasePrecision
(long precision, int mswDigits) private static int
private int
getDigits
(int x) private int
private int
getInitialDigits
(DataStorage dataStorage) private static long
getLeadingZeros
(DataStorage dataStorage, long index) private int
getLeastSignificantWord
(long index, int word) private long
private int
private static int
getMostSignificantWord
(DataStorage dataStorage) private long
getSize()
private static long
getTrailingZeros
(DataStorage dataStorage, long index) private int
getWord
(long index) private DataStorage.Iterator
getZeroPaddedIterator
(long start, long end) 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
.private static long
private void
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.private static void
writeZeros
(Writer out, long count) private ApfloatImpl
zero()
Methods inherited from class org.apfloat.internal.IntBaseMath
baseAdd, baseDivide, baseMultiplyAdd, baseSubtract
-
Field Details
-
ZERO_ITERATOR
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
UNDEFINED
private static final int UNDEFINED- See Also:
-
MAX_LONG_SIZE
private static final int MAX_LONG_SIZE- See Also:
-
MAX_DOUBLE_SIZE
private static final int MAX_DOUBLE_SIZE- See Also:
-
sign
private int sign -
precision
private long precision -
exponent
private long exponent -
dataStorage
-
radix
private int radix -
hashCode
private int hashCode -
initialDigits
private int initialDigits -
isOne
private int isOne -
leastZeros
private volatile long leastZeros -
size
private volatile long size
-
-
Constructor Details
-
IntApfloatImpl
-
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
-
readExponent
- Throws:
IOException
NumberFormatException
-
getTrailingZeros
private static long getTrailingZeros(DataStorage dataStorage, long index) throws ApfloatRuntimeException - Throws:
ApfloatRuntimeException
-
getLeadingZeros
private static long getLeadingZeros(DataStorage dataStorage, long index) throws ApfloatRuntimeException - Throws:
ApfloatRuntimeException
-
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
-
zero
-
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
-
getLeastZeros
- 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:
-
getZeroPaddedIterator
private DataStorage.Iterator getZeroPaddedIterator(long start, long end) throws ApfloatRuntimeException - Throws:
ApfloatRuntimeException
-
compareMantissaTo
- Throws:
ApfloatRuntimeException
-
findMismatch
private long findMismatch(DataStorage.Iterator thisIterator, DataStorage.Iterator thatIterator, long size) throws ApfloatRuntimeException - Throws:
ApfloatRuntimeException
-
getLeastSignificantWord
- Throws:
ApfloatRuntimeException
-
equals
Compares this object to the specified object. -
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:
-
writeZeros
- Throws:
IOException
-
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:
-
formatWord
private void formatWord(char[] buffer, int word) -
getSize
- Throws:
ApfloatRuntimeException
-
checkRadix
- Throws:
NumberFormatException
-
getMostSignificantWord
- Throws:
ApfloatRuntimeException
-
getMostSignificantWord
- Throws:
ApfloatRuntimeException
-
getInitialDigits
- Throws:
ApfloatRuntimeException
-
getInitialDigits
- Throws:
ApfloatRuntimeException
-
getDigits
private int getDigits(int x) -
getBasePrecision
- Throws:
ApfloatRuntimeException
-
getBasePrecision
private long getBasePrecision(long precision, int mswDigits) -
getWord
private int getWord(long index) -
readObject
- Throws:
IOException
ClassNotFoundException
-
createDataStorage
- Throws:
ApfloatRuntimeException
-
getBlockSize
private static int getBlockSize()
-