Class LongApfloatImpl
- All Implemented Interfaces:
Serializable, 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.
- Version:
- 1.11.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DataStorageprivate longprivate intprivate intprivate intprivate longprivate static final intprivate static final intprivate longprivate intprivate static final longprivate intprivate longprivate static final intprivate static final DataStorage.Iterator -
Constructor Summary
ConstructorsModifierConstructorDescriptionLongApfloatImpl(double value, long precision, int radix) Create a newLongApfloatImplinstance from adouble.privateLongApfloatImpl(int sign, long precision, long exponent, DataStorage dataStorage, int radix) LongApfloatImpl(long value, long precision, int radix) Create a newLongApfloatImplinstance from along.LongApfloatImpl(PushbackReader in, long precision, int radix, boolean isInteger) Create a newLongApfloatImplinstance reading from a stream.LongApfloatImpl(String value, long precision, int radix, boolean isInteger) Create a newLongApfloatImplinstance from a String. -
Method Summary
Modifier and TypeMethodDescriptionabsCeil()Returns thisApfloatImplrounded away from zero.absFloor()Returns thisApfloatImplrounded towards zero.addOrSubtract(ApfloatImpl x, boolean subtract) Add or subtract anApfloatImplto this object.private static intcheckRadix(int radix) private intintCompare thisApfloatImpland another number.private static DataStoragecreateDataStorage(long size) Divide thisApfloatImplby anApfloatImplthat is "short".doubleReturns the value of the this number as adouble.longThe number of equal digits in thisApfloatImpland another number.booleanCompares this object to the specified object.private longfindMismatch(DataStorage.Iterator thisIterator, DataStorage.Iterator thatIterator, long size) private voidformatWord(char[] buffer, long word) frac()Returns the fractional part of thisApfloatImpl.private longprivate longgetBasePrecision(long precision, int mswDigits) private static intprivate intgetDigits(long x) private intprivate intgetInitialDigits(DataStorage dataStorage) private static longgetLeadingZeros(DataStorage dataStorage, long index) private longgetLeastSignificantWord(long index, long word) private longprivate longprivate static longgetMostSignificantWord(DataStorage dataStorage) private longgetSize()private static longgetTrailingZeros(DataStorage dataStorage, long index) private longgetWord(long index) private DataStorage.IteratorgetZeroPaddedIterator(long start, long end) inthashCode()Returns the hash code for thisApfloatImpl.booleanisOne()Tests if this number is equal to 1.booleanisShort()Returns if thisApfloatImplis "short".longReturns the value of the this number as along.Multiply this object by anApfloatImpl.negate()Returns thisApfloatImplnegated.longReturns the precision of thisApfloatImpl.precision(long precision) Returns thisApfloatImplwith the specified precision.intradix()Returns the radix of thisApfloatImpl.private static longprivate voidlongscale()Returns the scale of thisApfloatImpl.intsignum()Returns the signum of thisApfloatImpl.longsize()Returns the size of the mantissa of thisApfloatImpl.toString(boolean pretty) Convert thisApfloatImpltoString.voidPrint thisApfloatImplto a stream.private static voidwriteZeros(Writer out, long count) private ApfloatImplzero()Methods inherited from class LongBaseMath
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
-
LongApfloatImpl
private LongApfloatImpl(int sign, long precision, long exponent, DataStorage dataStorage, int radix) -
LongApfloatImpl
public LongApfloatImpl(String value, long precision, int radix, boolean isInteger) throws NumberFormatException, ApfloatRuntimeException Create a newLongApfloatImplinstance 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
-
LongApfloatImpl
public LongApfloatImpl(long value, long precision, int radix) throws NumberFormatException, ApfloatRuntimeException Create a newLongApfloatImplinstance 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
-
LongApfloatImpl
public LongApfloatImpl(double value, long precision, int radix) throws NumberFormatException, ApfloatRuntimeException Create a newLongApfloatImplinstance 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
-
LongApfloatImpl
public LongApfloatImpl(PushbackReader in, long precision, int radix, boolean isInteger) throws IOException, NumberFormatException, ApfloatRuntimeException Create a newLongApfloatImplinstance reading from a stream.Implementation note: this constructor calls the
instream's single-characterread()method. If the underlying stream doesn't explicitly implement this method in some efficient way, but simply inherits it from theReaderbase class, performance will suffer as the defaultReadermethod 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:
IOExceptionNumberFormatException
-
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:ApfloatImplAdd or subtract anApfloatImplto this object.- Specified by:
addOrSubtractin interfaceApfloatImpl- Parameters:
x- The number to be added or subtracted to thisApfloatImpl.subtract-trueif the numbers are to be subtracted,falseif added.- Returns:
this + xorthis - xdepending on thesubtractargument.- Throws:
ApfloatRuntimeException
-
multiply
Description copied from interface:ApfloatImplMultiply this object by anApfloatImpl.- Specified by:
multiplyin interfaceApfloatImpl- Parameters:
x- The number to be multiplied by thisApfloatImpl.- Returns:
this * x.- Throws:
ApfloatRuntimeException
-
isShort
Description copied from interface:ApfloatImplReturns if thisApfloatImplis "short". TypicallyApfloatImplis "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:
isShortin interfaceApfloatImpl- Returns:
trueif theApfloatImplis "short",falseif not.- Throws:
ApfloatRuntimeException- See Also:
-
divideShort
Description copied from interface:ApfloatImplDivide thisApfloatImplby anApfloatImplthat is "short".- Specified by:
divideShortin interfaceApfloatImpl- Parameters:
x- The number by which thisApfloatImplis to be divided.- Returns:
this / x.- Throws:
ApfloatRuntimeException
-
absFloor
Description copied from interface:ApfloatImplReturns thisApfloatImplrounded towards zero.- Specified by:
absFloorin interfaceApfloatImpl- Returns:
- This
ApfloatImplrounded towards zero. - Throws:
ApfloatRuntimeException
-
absCeil
Description copied from interface:ApfloatImplReturns thisApfloatImplrounded away from zero.- Specified by:
absCeilin interfaceApfloatImpl- Returns:
- This
ApfloatImplrounded away from zero. - Throws:
ApfloatRuntimeException
-
frac
Description copied from interface:ApfloatImplReturns the fractional part of thisApfloatImpl.- Specified by:
fracin interfaceApfloatImpl- Returns:
- The fractional part of this
ApfloatImpl. - Throws:
ApfloatRuntimeException
-
zero
-
radix
public int radix()Description copied from interface:ApfloatImplReturns the radix of thisApfloatImpl.- Specified by:
radixin interfaceApfloatImpl- Returns:
- The radix of this
ApfloatImpl.
-
precision
public long precision()Description copied from interface:ApfloatImplReturns the precision of thisApfloatImpl.- Specified by:
precisionin interfaceApfloatImpl- Returns:
- The precision of this
ApfloatImpl.
-
size
Description copied from interface:ApfloatImplReturns the size of the mantissa of thisApfloatImpl.- Specified by:
sizein interfaceApfloatImpl- Returns:
- The size of the mantissa of this
ApfloatImpl. - Throws:
ApfloatRuntimeException
-
getLeastZeros
- Throws:
ApfloatRuntimeException
-
precision
Description copied from interface:ApfloatImplReturns thisApfloatImplwith the specified precision.- Specified by:
precisionin interfaceApfloatImpl- Parameters:
precision- The precision.- Returns:
- This
ApfloatImplwith the specified precision.
-
scale
Description copied from interface:ApfloatImplReturns the scale of thisApfloatImpl.- Specified by:
scalein interfaceApfloatImpl- Returns:
- The scale of this
ApfloatImpl. - Throws:
ApfloatRuntimeException- See Also:
-
signum
public int signum()Description copied from interface:ApfloatImplReturns the signum of thisApfloatImpl.- Specified by:
signumin interfaceApfloatImpl- Returns:
- The signum of this
ApfloatImpl. - See Also:
-
negate
Description copied from interface:ApfloatImplReturns thisApfloatImplnegated.- Specified by:
negatein interfaceApfloatImpl- Returns:
-this.- Throws:
ApfloatRuntimeException
-
doubleValue
public double doubleValue()Description copied from interface:ApfloatImplReturns the value of the this number as adouble. If the number is greater thanDouble.MAX_VALUE, thenDouble.POSITIVE_INFINITYis returned.If the number is less than
Double.MIN_VALUE, thenDouble.NEGATIVE_INFINITYis returned.If the number is very small in magnitude, underflow may happen and zero is returned.
- Specified by:
doubleValuein interfaceApfloatImpl- Returns:
- The numeric value represented by this object after conversion to type
double.
-
longValue
public long longValue()Description copied from interface:ApfloatImplReturns 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_VALUEis returned.If the number is less than
Long.MIN_VALUE, thenLong.MIN_VALUEis returned.- Specified by:
longValuein interfaceApfloatImpl- Returns:
- The numeric value represented by this object after conversion to type
long.
-
isOne
Description copied from interface:ApfloatImplTests if this number is equal to 1.- Specified by:
isOnein interfaceApfloatImpl- Returns:
trueif this number is equal to one, otherwisefalse.- Throws:
ApfloatRuntimeException
-
equalDigits
Description copied from interface:ApfloatImplThe number of equal digits in thisApfloatImpland another number.- Specified by:
equalDigitsin interfaceApfloatImpl- Parameters:
x- The number to compare with.- Returns:
- The number of equal digits in this
ApfloatImplandx. - Throws:
ApfloatRuntimeException- See Also:
-
compareTo
Description copied from interface:ApfloatImplCompare thisApfloatImpland another number.- Specified by:
compareToin 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
-
hashCode
public int hashCode()Description copied from interface:ApfloatImplReturns the hash code for thisApfloatImpl.- Specified by:
hashCodein interfaceApfloatImpl- Overrides:
hashCodein classObject- Returns:
- The hash code for this
ApfloatImpl.
-
toString
Description copied from interface:ApfloatImplConvert thisApfloatImpltoString.- Specified by:
toStringin interfaceApfloatImpl- Parameters:
pretty- Flag for formatting.- Returns:
- String representation of this
ApfloatImpl. - Throws:
ApfloatRuntimeException- See Also:
-
writeZeros
- Throws:
IOException
-
writeTo
Description copied from interface:ApfloatImplPrint thisApfloatImplto a stream.- Specified by:
writeToin 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, long word) -
getSize
- Throws:
ApfloatRuntimeException
-
checkRadix
- Throws:
NumberFormatException
-
getMostSignificantWord
- Throws:
ApfloatRuntimeException
-
getMostSignificantWord
- Throws:
ApfloatRuntimeException
-
getInitialDigits
- Throws:
ApfloatRuntimeException
-
getInitialDigits
- Throws:
ApfloatRuntimeException
-
getDigits
private int getDigits(long x) -
getBasePrecision
- Throws:
ApfloatRuntimeException
-
getBasePrecision
private long getBasePrecision(long precision, int mswDigits) -
getWord
private long getWord(long index) -
readObject
- Throws:
IOExceptionClassNotFoundException
-
createDataStorage
- Throws:
ApfloatRuntimeException
-
getBlockSize
private static int getBlockSize()
-