Class ApfloatHelper
java.lang.Object
org.apfloat.ApfloatHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Apcomplexstatic Apfloatprivate 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(PushbackReader in, boolean isInteger) static ApfloatImplcreateApfloat(PushbackReader in, long precision, boolean isInteger) static ApfloatImplcreateApfloat(PushbackReader in, long precision, int radix, boolean isInteger) static ApfloatImplcreateApfloat(String value, boolean isInteger) static ApfloatImplcreateApfloat(String value, long precision, boolean isInteger) static ApfloatImplcreateApfloat(String value, long precision, int radix, boolean isInteger) static ApfloatImplcreateApfloat(BigDecimal value) static ApfloatImplcreateApfloat(BigDecimal value, long precision) static ApfloatImplcreateApfloat(BigInteger value) static ApfloatImplcreateApfloat(BigInteger value, long precision) static ApfloatImplcreateApfloat(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 Apcomplexstatic ApcomplexextendPrecision(Apcomplex z, long extraPrecision) static Apfloatstatic ApfloatextendPrecision(Apfloat x, long extraPrecision) static voidExtracts whitespace from stream.private static ApfloatBuilderprivate static intstatic intgetDoublePrecision(int radix) static intgetFloatPrecision(int radix) static intgetLongPrecision(int radix) static long[]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(PushbackReader in, long precision, int radix, boolean isInteger) private static ApfloatImplimplCreateApfloat(String value, long precision, int radix, boolean isInteger) static ApcomplexlimitPrecision(Apcomplex z, long precision) static ApfloatlimitPrecision(Apfloat x, long precision) static longstatic booleanreadMatch(PushbackReader in, int c) Extracts matching character from stream.static longreducePrecision(long precision) static longreducePrecision(long precision, long extraPrecision) static Apcomplexstatic ApcomplexreducePrecision(Apcomplex z, long extraPrecision) static Apfloatstatic ApfloatreducePrecision(Apfloat x, long extraPrecision) static ApcomplexsetPrecision(Apcomplex z, long precision) static longsize(Aprational x) static BigIntegerstatic PushbackReader
-
Constructor Details
-
ApfloatHelper
private ApfloatHelper()
-
-
Method Details
-
createApfloat
public static ApfloatImpl createApfloat(String value, boolean isInteger) throws NumberFormatException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(String value, long precision, boolean isInteger) throws NumberFormatException, IllegalArgumentException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(String value, long precision, int radix, boolean isInteger) throws NumberFormatException, IllegalArgumentException, ApfloatRuntimeException -
implCreateApfloat
private static ApfloatImpl implCreateApfloat(String value, long precision, int radix, boolean isInteger) throws NumberFormatException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(long value) throws NumberFormatException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(long value, long precision) throws NumberFormatException, IllegalArgumentException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(long value, long precision, int radix) throws NumberFormatException, IllegalArgumentException, ApfloatRuntimeException -
implCreateApfloat
private static ApfloatImpl implCreateApfloat(long value, long precision, int radix) throws NumberFormatException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(float value) throws NumberFormatException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(float value, long precision) throws NumberFormatException, IllegalArgumentException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(float value, long precision, int radix) throws NumberFormatException, IllegalArgumentException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(double value) throws NumberFormatException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(double value, long precision) throws NumberFormatException, IllegalArgumentException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(double value, long precision, int radix) throws NumberFormatException, IllegalArgumentException, ApfloatRuntimeException -
implCreateApfloat
private static ApfloatImpl implCreateApfloat(double value, long precision, int radix) throws NumberFormatException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(PushbackReader in, boolean isInteger) throws IOException, NumberFormatException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(PushbackReader in, long precision, boolean isInteger) throws IOException, NumberFormatException, IllegalArgumentException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(PushbackReader in, long precision, int radix, boolean isInteger) throws IOException, NumberFormatException, IllegalArgumentException, ApfloatRuntimeException -
implCreateApfloat
private static ApfloatImpl implCreateApfloat(PushbackReader in, long precision, int radix, boolean isInteger) throws IOException, NumberFormatException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(BigInteger value) throws NumberFormatException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(BigInteger value, long precision) throws NumberFormatException, IllegalArgumentException, ApfloatRuntimeException -
createApfloat
public static ApfloatImpl createApfloat(BigInteger value, long precision, int radix) throws NumberFormatException, IllegalArgumentException, ApfloatRuntimeException -
createApfloat
- Throws:
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(BigDecimal value, long precision) throws IllegalArgumentException, ApfloatRuntimeException -
readMatch
Extracts 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:
IOException- In case of read error in the stream.
-
extractWhitespace
Extracts whitespace from stream.- Parameters:
in- The input.- Throws:
IOException- In case of read error in the stream.
-
getMatchingPrecisions
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
- Throws:
IllegalArgumentException
-
checkRadix
- Throws:
NumberFormatException
-
checkPowPrecision
- Throws:
InfiniteExpansionException
-
checkPowBasic
private static Apcomplex checkPowBasic(Apcomplex z, Apcomplex w, long targetPrecision) throws ArithmeticException, ApfloatRuntimeException -
checkPow
public static Apcomplex checkPow(Apcomplex z, Apcomplex w, long targetPrecision) throws ArithmeticException, ApfloatRuntimeException -
checkPow
public static Apfloat checkPow(Apfloat x, Apfloat y, long targetPrecision) throws ArithmeticException, ApfloatRuntimeException -
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
- Throws:
ApfloatRuntimeException
-
ensurePrecision
- 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
- Throws:
ApfloatRuntimeException
-
extendPrecision
- Throws:
ApfloatRuntimeException
-
extendPrecision
public static Apfloat extendPrecision(Apfloat x, long extraPrecision) throws ApfloatRuntimeException - Throws:
ApfloatRuntimeException
-
reducePrecision
- Throws:
ApfloatRuntimeException
-
reducePrecision
public static Apfloat reducePrecision(Apfloat x, long extraPrecision) throws ApfloatRuntimeException - Throws:
ApfloatRuntimeException
-
setPrecision
- Throws:
ApfloatRuntimeException
-
limitPrecision
- Throws:
ApfloatRuntimeException
-
ensurePrecision
- Throws:
ApfloatRuntimeException
-
extendPrecision
- Throws:
ApfloatRuntimeException
-
extendPrecision
public static Apcomplex extendPrecision(Apcomplex z, long extraPrecision) throws ApfloatRuntimeException - Throws:
ApfloatRuntimeException
-
reducePrecision
- Throws:
ApfloatRuntimeException
-
reducePrecision
public static Apcomplex reducePrecision(Apcomplex z, long extraPrecision) throws ApfloatRuntimeException - Throws:
ApfloatRuntimeException
-
ensureGammaPrecision
-
size
- Throws:
ApfloatRuntimeException
-
toBigInteger
-
toPushbackReader
- Throws:
IOException
-
longValueExact
- Throws:
OverflowException
-
getDefaultRadix
- Throws:
NumberFormatException
-
getApfloatBuilder
-