Package org.apfloat
Class ApfloatHelper
- java.lang.Object
-
- org.apfloat.ApfloatHelper
-
class ApfloatHelper extends java.lang.ObjectVarious utility methods related to apfloats.- Version:
- 1.14.0
-
-
Constructor Summary
Constructors Modifier Constructor Description privateApfloatHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ApcomplexcheckPow(Apcomplex z, Apcomplex w, long targetPrecision)static ApfloatcheckPow(Apfloat x, Apfloat y, long targetPrecision)private static ApcomplexcheckPowBasic(Apcomplex z, Apcomplex w, long targetPrecision)private static voidcheckPowPrecision(long targetPrecision)static voidcheckPrecision(long precision)static voidcheckRadix(int radix)static ApfloatImplcreateApfloat(double value)static ApfloatImplcreateApfloat(double value, long precision)static ApfloatImplcreateApfloat(double value, long precision, int radix)static ApfloatImplcreateApfloat(float value)static ApfloatImplcreateApfloat(float value, long precision)static ApfloatImplcreateApfloat(float value, long precision, int radix)static ApfloatImplcreateApfloat(long value)static ApfloatImplcreateApfloat(long value, long precision)static ApfloatImplcreateApfloat(long value, long precision, int radix)static ApfloatImplcreateApfloat(java.io.PushbackReader in, boolean isInteger)static ApfloatImplcreateApfloat(java.io.PushbackReader in, long precision, boolean isInteger)static ApfloatImplcreateApfloat(java.io.PushbackReader in, long precision, int radix, boolean isInteger)static ApfloatImplcreateApfloat(java.lang.String value, boolean isInteger)static ApfloatImplcreateApfloat(java.lang.String value, long precision, boolean isInteger)static ApfloatImplcreateApfloat(java.lang.String value, long precision, int radix, boolean isInteger)static ApfloatImplcreateApfloat(java.math.BigDecimal value)static ApfloatImplcreateApfloat(java.math.BigDecimal value, long precision)static ApfloatImplcreateApfloat(java.math.BigInteger value)static ApfloatImplcreateApfloat(java.math.BigInteger value, long precision)static ApfloatImplcreateApfloat(java.math.BigInteger value, long precision, int radix)static ApcomplexensureGammaPrecision(Apcomplex z, long precision)static ApcomplexensurePrecision(Apcomplex z, long precision)static ApfloatensurePrecision(Apfloat x, long precision)static longextendPrecision(long precision)static longextendPrecision(long precision, long extraPrecision)static ApcomplexextendPrecision(Apcomplex z)static ApcomplexextendPrecision(Apcomplex z, long extraPrecision)static ApfloatextendPrecision(Apfloat x)static ApfloatextendPrecision(Apfloat x, long extraPrecision)static voidextractWhitespace(java.io.PushbackReader in)Extracts whitespace from stream.private static ApfloatBuildergetApfloatBuilder()private static intgetDefaultRadix()static intgetDoublePrecision(int radix)static intgetFloatPrecision(int radix)static intgetLongPrecision(int radix)static long[]getMatchingPrecisions(Apfloat x, Apfloat y)Get working precisions for the arguments of e.g.static long[]getMatchingPrecisions(Apfloat a, Apfloat b, Apfloat c, Apfloat d)Get working precisions for the arguments of an multiply-add operation a * b + c * d.static longgetSmallExtraPrecision(int radix)private static ApfloatImplimplCreateApfloat(double value, long precision, int radix)private static ApfloatImplimplCreateApfloat(long value, long precision, int radix)private static ApfloatImplimplCreateApfloat(java.io.PushbackReader in, long precision, int radix, boolean isInteger)private static ApfloatImplimplCreateApfloat(java.lang.String value, long precision, int radix, boolean isInteger)static ApcomplexlimitPrecision(Apcomplex z, long precision)static ApfloatlimitPrecision(Apfloat x, long precision)static longlongValueExact(Apint x)static booleanreadMatch(java.io.PushbackReader in, int c)Extracts matching character from stream.static longreducePrecision(long precision)static longreducePrecision(long precision, long extraPrecision)static ApcomplexreducePrecision(Apcomplex z)static ApcomplexreducePrecision(Apcomplex z, long extraPrecision)static ApfloatreducePrecision(Apfloat x)static ApfloatreducePrecision(Apfloat x, long extraPrecision)static ApcomplexsetPrecision(Apcomplex z, long precision)static longsize(Aprational x)static java.math.BigIntegertoBigInteger(Apint x)static java.io.PushbackReadertoPushbackReader(java.math.BigInteger x)
-
-
-
Method Detail
-
createApfloat
public static ApfloatImpl createApfloat(java.lang.String value, boolean isInteger) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.lang.String value, long precision, boolean isInteger) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.lang.String value, long precision, int radix, boolean isInteger) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionApfloatRuntimeException
-
implCreateApfloat
private static ApfloatImpl implCreateApfloat(java.lang.String value, long precision, int radix, boolean isInteger) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(long value) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(long value, long precision) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(long value, long precision, int radix) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionApfloatRuntimeException
-
implCreateApfloat
private static ApfloatImpl implCreateApfloat(long value, long precision, int radix) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(float value) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(float value, long precision) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(float value, long precision, int radix) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(double value) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(double value, long precision) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(double value, long precision, int radix) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionApfloatRuntimeException
-
implCreateApfloat
private static ApfloatImpl implCreateApfloat(double value, long precision, int radix) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.io.PushbackReader in, boolean isInteger) throws java.io.IOException, java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.io.IOExceptionjava.lang.NumberFormatExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.io.PushbackReader in, long precision, boolean isInteger) throws java.io.IOException, java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.io.IOExceptionjava.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.io.PushbackReader in, long precision, int radix, boolean isInteger) throws java.io.IOException, java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.io.IOExceptionjava.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionApfloatRuntimeException
-
implCreateApfloat
private static ApfloatImpl implCreateApfloat(java.io.PushbackReader in, long precision, int radix, boolean isInteger) throws java.io.IOException, java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.io.IOExceptionjava.lang.NumberFormatExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.math.BigInteger value) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.math.BigInteger value, long precision) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.math.BigInteger value, long precision, int radix) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.math.BigDecimal value) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.math.BigDecimal value, long precision) throws java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.IllegalArgumentExceptionApfloatRuntimeException
-
readMatch
public static boolean readMatch(java.io.PushbackReader in, int c) throws java.io.IOExceptionExtracts matching character from stream. A non-matching character is pushed back to the stream.- Parameters:
in- The input.c- The character to expect from the stream.- Returns:
trueif the specified character was extracted from the stream,falseotherwise.- Throws:
java.io.IOException- In case of read error in the stream.
-
extractWhitespace
public static void extractWhitespace(java.io.PushbackReader in) throws java.io.IOExceptionExtracts whitespace from stream.- Parameters:
in- The input.- Throws:
java.io.IOException- In case of read error in the stream.
-
getMatchingPrecisions
public static long[] getMatchingPrecisions(Apfloat x, Apfloat y) throws ApfloatRuntimeException
Get working precisions for the arguments of e.g. an add, subtract or compare operation.Note that the returned precision can be zero to indicate that the number is insignificant in the calculation. This is the case if either operand is zero, or if one number lies completely outside the significant range of the other number. Consider e.g. the case
x.scale() = 100
x.precision() = 50
y.scale() = 10
y.precision() = 5In e.g. the sum of x and y, the operand y would now be insignificant.
- Parameters:
x- First argument.y- Second argument.- Returns:
- Array of two longs containing the working precisions for
xandy, correspondingly. - Throws:
ApfloatRuntimeException
-
getMatchingPrecisions
public static long[] getMatchingPrecisions(Apfloat a, Apfloat b, Apfloat c, Apfloat d) throws ApfloatRuntimeException
Get working precisions for the arguments of an multiply-add operation a * b + c * d. Works as well for a multiply-subtract operation, of course.The returned array contains three longs:
[0] Working precisions for
aandb
[1] Working precisions forcandd
[2] Maximum precision of the final resulta * b + c * dNote that the precisions can be zero. See
getMatchingPrecisions(Apfloat,Apfloat)for details.- Parameters:
a- First argument.b- Second argument.c- Third argument.d- Fourth argument.- Returns:
- Array of three longs containing the precisions.
- Throws:
ApfloatRuntimeException
-
checkPrecision
public static void checkPrecision(long precision) throws java.lang.IllegalArgumentException- Throws:
java.lang.IllegalArgumentException
-
checkRadix
public static void checkRadix(int radix) throws java.lang.NumberFormatException- Throws:
java.lang.NumberFormatException
-
checkPowPrecision
private static void checkPowPrecision(long targetPrecision) throws InfiniteExpansionException- Throws:
InfiniteExpansionException
-
checkPowBasic
private static Apcomplex checkPowBasic(Apcomplex z, Apcomplex w, long targetPrecision) throws java.lang.ArithmeticException, ApfloatRuntimeException
- Throws:
java.lang.ArithmeticExceptionApfloatRuntimeException
-
checkPow
public static Apcomplex checkPow(Apcomplex z, Apcomplex w, long targetPrecision) throws java.lang.ArithmeticException, ApfloatRuntimeException
- Throws:
java.lang.ArithmeticExceptionApfloatRuntimeException
-
checkPow
public static Apfloat checkPow(Apfloat x, Apfloat y, long targetPrecision) throws java.lang.ArithmeticException, ApfloatRuntimeException
- Throws:
java.lang.ArithmeticExceptionApfloatRuntimeException
-
getFloatPrecision
public static int getFloatPrecision(int radix)
-
getDoublePrecision
public static int getDoublePrecision(int radix)
-
getLongPrecision
public static int getLongPrecision(int radix)
-
getSmallExtraPrecision
public static long getSmallExtraPrecision(int radix)
-
limitPrecision
public static Apfloat limitPrecision(Apfloat x, long precision) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
ensurePrecision
public static Apfloat ensurePrecision(Apfloat x, long precision) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
extendPrecision
public static long extendPrecision(long precision, long extraPrecision)
-
extendPrecision
public static long extendPrecision(long precision)
-
reducePrecision
public static long reducePrecision(long precision, long extraPrecision) throws ApfloatRuntimeException- Throws:
ApfloatRuntimeException
-
reducePrecision
public static long reducePrecision(long precision) throws ApfloatRuntimeException- Throws:
ApfloatRuntimeException
-
extendPrecision
public static Apfloat extendPrecision(Apfloat x) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
extendPrecision
public static Apfloat extendPrecision(Apfloat x, long extraPrecision) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
reducePrecision
public static Apfloat reducePrecision(Apfloat x) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
reducePrecision
public static Apfloat reducePrecision(Apfloat x, long extraPrecision) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
setPrecision
public static Apcomplex setPrecision(Apcomplex z, long precision) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
limitPrecision
public static Apcomplex limitPrecision(Apcomplex z, long precision) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
ensurePrecision
public static Apcomplex ensurePrecision(Apcomplex z, long precision) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
extendPrecision
public static Apcomplex extendPrecision(Apcomplex z) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
extendPrecision
public static Apcomplex extendPrecision(Apcomplex z, long extraPrecision) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
reducePrecision
public static Apcomplex reducePrecision(Apcomplex z) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
reducePrecision
public static Apcomplex reducePrecision(Apcomplex z, long extraPrecision) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
size
public static long size(Aprational x) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
toBigInteger
public static java.math.BigInteger toBigInteger(Apint x)
-
toPushbackReader
public static java.io.PushbackReader toPushbackReader(java.math.BigInteger x) throws java.io.IOException- Throws:
java.io.IOException
-
longValueExact
public static long longValueExact(Apint x) throws OverflowException
- Throws:
OverflowException
-
getDefaultRadix
private static int getDefaultRadix() throws java.lang.NumberFormatException- Throws:
java.lang.NumberFormatException
-
getApfloatBuilder
private static ApfloatBuilder getApfloatBuilder()
-
-