Class DoubleApfloatImpl
- All Implemented Interfaces:
Serializable,ApfloatImpl
double 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
ConstructorsConstructorDescriptionDoubleApfloatImpl(double value, long precision, int radix) Create a newDoubleApfloatImplinstance from adouble.DoubleApfloatImpl(long value, long precision, int radix) Create a newDoubleApfloatImplinstance from along.DoubleApfloatImpl(PushbackReader in, long precision, int radix, boolean isInteger) Create a newDoubleApfloatImplinstance reading from a stream.DoubleApfloatImpl(String value, long precision, int radix, boolean isInteger) Create a newDoubleApfloatImplinstance 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.intCompare thisApfloatImpland another number.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.frac()Returns the fractional part of thisApfloatImpl.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.longscale()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.Methods inherited from class org.apfloat.internal.DoubleBaseMath
baseAdd, baseDivide, baseMultiplyAdd, baseSubtract
-
Constructor Details
-
DoubleApfloatImpl
public DoubleApfloatImpl(String value, long precision, int radix, boolean isInteger) throws NumberFormatException, ApfloatRuntimeException Create a newDoubleApfloatImplinstance 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
-
DoubleApfloatImpl
public DoubleApfloatImpl(long value, long precision, int radix) throws NumberFormatException, ApfloatRuntimeException Create a newDoubleApfloatImplinstance 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
-
DoubleApfloatImpl
public DoubleApfloatImpl(double value, long precision, int radix) throws NumberFormatException, ApfloatRuntimeException Create a newDoubleApfloatImplinstance 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
-
DoubleApfloatImpl
public DoubleApfloatImpl(PushbackReader in, long precision, int radix, boolean isInteger) throws IOException, NumberFormatException, ApfloatRuntimeException Create a newDoubleApfloatImplinstance 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
-
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
-
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
-
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:
-
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:
-
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:
-