Package org.apfloat
Class ApfloatHelper
- java.lang.Object
-
- org.apfloat.ApfloatHelper
-
class ApfloatHelper extends java.lang.Object
Various utility methods related to apfloats.- Version:
- 1.14.0
-
-
Constructor Summary
Constructors Modifier Constructor Description private
ApfloatHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Apcomplex
checkPow(Apcomplex z, Apcomplex w, long targetPrecision)
static Apfloat
checkPow(Apfloat x, Apfloat y, long targetPrecision)
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(java.io.PushbackReader in, boolean isInteger)
static ApfloatImpl
createApfloat(java.io.PushbackReader in, long precision, boolean isInteger)
static ApfloatImpl
createApfloat(java.io.PushbackReader in, long precision, int radix, boolean isInteger)
static ApfloatImpl
createApfloat(java.lang.String value, boolean isInteger)
static ApfloatImpl
createApfloat(java.lang.String value, long precision, boolean isInteger)
static ApfloatImpl
createApfloat(java.lang.String value, long precision, int radix, boolean isInteger)
static ApfloatImpl
createApfloat(java.math.BigDecimal value)
static ApfloatImpl
createApfloat(java.math.BigDecimal value, long precision)
static ApfloatImpl
createApfloat(java.math.BigInteger value)
static ApfloatImpl
createApfloat(java.math.BigInteger value, long precision)
static ApfloatImpl
createApfloat(java.math.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
extendPrecision(Apcomplex z)
static Apcomplex
extendPrecision(Apcomplex z, long extraPrecision)
static Apfloat
extendPrecision(Apfloat x)
static Apfloat
extendPrecision(Apfloat x, long extraPrecision)
static void
extractWhitespace(java.io.PushbackReader in)
Extracts whitespace from stream.private static ApfloatBuilder
getApfloatBuilder()
private static int
getDefaultRadix()
static int
getDoublePrecision(int radix)
static int
getFloatPrecision(int radix)
static int
getLongPrecision(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 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(java.io.PushbackReader in, long precision, int radix, boolean isInteger)
private static ApfloatImpl
implCreateApfloat(java.lang.String value, long precision, int radix, boolean isInteger)
static Apcomplex
limitPrecision(Apcomplex z, long precision)
static Apfloat
limitPrecision(Apfloat x, long precision)
static long
longValueExact(Apint x)
static boolean
readMatch(java.io.PushbackReader in, int c)
Extracts matching character from stream.static long
reducePrecision(long precision)
static long
reducePrecision(long precision, long extraPrecision)
static Apcomplex
reducePrecision(Apcomplex z)
static Apcomplex
reducePrecision(Apcomplex z, long extraPrecision)
static Apfloat
reducePrecision(Apfloat x)
static Apfloat
reducePrecision(Apfloat x, long extraPrecision)
static Apcomplex
setPrecision(Apcomplex z, long precision)
static long
size(Aprational x)
static java.math.BigInteger
toBigInteger(Apint x)
static java.io.PushbackReader
toPushbackReader(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.NumberFormatException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.lang.String value, long precision, boolean isInteger) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
java.lang.IllegalArgumentException
ApfloatRuntimeException
-
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.NumberFormatException
java.lang.IllegalArgumentException
ApfloatRuntimeException
-
implCreateApfloat
private static ApfloatImpl implCreateApfloat(java.lang.String value, long precision, int radix, boolean isInteger) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(long value) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(long value, long precision) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
java.lang.IllegalArgumentException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(long value, long precision, int radix) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
java.lang.IllegalArgumentException
ApfloatRuntimeException
-
implCreateApfloat
private static ApfloatImpl implCreateApfloat(long value, long precision, int radix) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(float value) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(float value, long precision) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
java.lang.IllegalArgumentException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(float value, long precision, int radix) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
java.lang.IllegalArgumentException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(double value) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(double value, long precision) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
java.lang.IllegalArgumentException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(double value, long precision, int radix) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
java.lang.IllegalArgumentException
ApfloatRuntimeException
-
implCreateApfloat
private static ApfloatImpl implCreateApfloat(double value, long precision, int radix) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.io.PushbackReader in, boolean isInteger) throws java.io.IOException, java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.io.IOException
java.lang.NumberFormatException
ApfloatRuntimeException
-
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.IOException
java.lang.NumberFormatException
java.lang.IllegalArgumentException
ApfloatRuntimeException
-
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.IOException
java.lang.NumberFormatException
java.lang.IllegalArgumentException
ApfloatRuntimeException
-
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.IOException
java.lang.NumberFormatException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.math.BigInteger value) throws java.lang.NumberFormatException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.math.BigInteger value, long precision) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
java.lang.IllegalArgumentException
ApfloatRuntimeException
-
createApfloat
public static ApfloatImpl createApfloat(java.math.BigInteger value, long precision, int radix) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
- Throws:
java.lang.NumberFormatException
java.lang.IllegalArgumentException
ApfloatRuntimeException
-
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.IllegalArgumentException
ApfloatRuntimeException
-
readMatch
public static boolean readMatch(java.io.PushbackReader in, int c) throws java.io.IOException
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:
java.io.IOException
- In case of read error in the stream.
-
extractWhitespace
public static void extractWhitespace(java.io.PushbackReader in) throws java.io.IOException
Extracts 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
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
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.ArithmeticException
ApfloatRuntimeException
-
checkPow
public static Apcomplex checkPow(Apcomplex z, Apcomplex w, long targetPrecision) throws java.lang.ArithmeticException, ApfloatRuntimeException
- Throws:
java.lang.ArithmeticException
ApfloatRuntimeException
-
checkPow
public static Apfloat checkPow(Apfloat x, Apfloat y, long targetPrecision) throws java.lang.ArithmeticException, ApfloatRuntimeException
- Throws:
java.lang.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
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()
-
-