Package org.apfloat
Class ApfloatHelper
java.lang.Object
org.apfloat.ApfloatHelper
Various utility methods related to apfloats.
- Version:
- 1.14.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Apcomplex
static Apfloat
private static Apcomplex
checkPowBasic
(Apcomplex z, Apcomplex w, long targetPrecision) private static void
checkPowPrecision
(long targetPrecision) static void
checkPrecision
(long precision) static void
checkRadix
(int radix) static ApfloatImpl
createApfloat
(double value) static ApfloatImpl
createApfloat
(double value, long precision) static ApfloatImpl
createApfloat
(double value, long precision, int radix) static ApfloatImpl
createApfloat
(float value) static ApfloatImpl
createApfloat
(float value, long precision) static ApfloatImpl
createApfloat
(float value, long precision, int radix) static ApfloatImpl
createApfloat
(long value) static ApfloatImpl
createApfloat
(long value, long precision) static ApfloatImpl
createApfloat
(long value, long precision, int radix) static ApfloatImpl
createApfloat
(PushbackReader in, boolean isInteger) static ApfloatImpl
createApfloat
(PushbackReader in, long precision, boolean isInteger) static ApfloatImpl
createApfloat
(PushbackReader in, long precision, int radix, boolean isInteger) static ApfloatImpl
createApfloat
(String value, boolean isInteger) static ApfloatImpl
createApfloat
(String value, long precision, boolean isInteger) static ApfloatImpl
createApfloat
(String value, long precision, int radix, boolean isInteger) static ApfloatImpl
createApfloat
(BigDecimal value) static ApfloatImpl
createApfloat
(BigDecimal value, long precision) static ApfloatImpl
createApfloat
(BigInteger value) static ApfloatImpl
createApfloat
(BigInteger value, long precision) static ApfloatImpl
createApfloat
(BigInteger value, long precision, int radix) static Apcomplex
ensureGammaPrecision
(Apcomplex z, long precision) static Apcomplex
ensurePrecision
(Apcomplex z, long precision) static Apfloat
ensurePrecision
(Apfloat x, long precision) static long
extendPrecision
(long precision) static long
extendPrecision
(long precision, long extraPrecision) static Apcomplex
static Apcomplex
extendPrecision
(Apcomplex z, long extraPrecision) static Apfloat
static Apfloat
extendPrecision
(Apfloat x, long extraPrecision) static void
Extracts whitespace from stream.private static ApfloatBuilder
private static int
static int
getDoublePrecision
(int radix) static int
getFloatPrecision
(int radix) static int
getLongPrecision
(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 long
getSmallExtraPrecision
(int radix) private static ApfloatImpl
implCreateApfloat
(double value, long precision, int radix) private static ApfloatImpl
implCreateApfloat
(long value, long precision, int radix) private static ApfloatImpl
implCreateApfloat
(PushbackReader in, long precision, int radix, boolean isInteger) private static ApfloatImpl
implCreateApfloat
(String value, long precision, int radix, boolean isInteger) static Apcomplex
limitPrecision
(Apcomplex z, long precision) static Apfloat
limitPrecision
(Apfloat x, long precision) static long
static boolean
readMatch
(PushbackReader in, int c) Extracts matching character from stream.static long
reducePrecision
(long precision) static long
reducePrecision
(long precision, long extraPrecision) static Apcomplex
static Apcomplex
reducePrecision
(Apcomplex z, long extraPrecision) static Apfloat
static Apfloat
reducePrecision
(Apfloat x, long extraPrecision) static Apcomplex
setPrecision
(Apcomplex z, long precision) static long
size
(Aprational x) static BigInteger
static 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:
true
if the specified character was extracted from the stream,false
otherwise.- 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
x
andy
, 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
a
andb
[1] Working precisions forc
andd
[2] Maximum precision of the final resulta * b + c * d
Note 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
-