Package org.apfloat
Class Apint
java.lang.Object
java.lang.Number
org.apfloat.Apcomplex
org.apfloat.Apfloat
org.apfloat.Aprational
org.apfloat.Apint
- All Implemented Interfaces:
Serializable,Comparable<Apfloat>,Formattable
Arbitrary precision integer class.
In addition to the constructors, it is possible to create an apint
from an apfloat or aprational via the methods that round these
numbers to an integer value: Apfloat.floor(), Apfloat.ceil(),
and Apfloat.truncate().
- Version:
- 1.10.1
- Author:
- Mikko Tommila
- See Also:
-
Field Summary
Fields inherited from class org.apfloat.Apcomplex
DEFAULT, I, INFINITE, ONE, REAL_ABS_IMAG_ORDER, REAL_IMAG_ORDER, ZERO -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedApint()Default constructor.Apint(long value) Constructs an apfloat from the specifiedlong.Apint(long value, int radix) Constructs an apfloat from the specifiedlongand radix.Apint(PushbackReader in) Reads an apint from a stream using the default radix.Apint(PushbackReader in, int radix) Reads an apint from a stream using the specified radix.Constructs an apfloat from the specified string.Constructs an apfloat from the specified string and radix.Apint(BigInteger value) Constructs an apint from aBigInteger.Apint(BigInteger value, int radix) Constructs an apint from aBigIntegerusing the specified radix. -
Method Summary
Modifier and TypeMethodDescriptionAdds two apints.ceil()Ceiling function.intCompare this apint to the specified apfloat.intCompare this apint to the specified apint.intCompare this apint to the specified aprational.Denominator of this aprational.Divides two apints.booleanCompares this object to the specified object.floor()Floor function.voidFormats the object using the provided formatter.frac()Returns the fractional part.protected ApfloatImplgetImpl(long precision) Returns anApfloatImplrepresenting this apint up to the requested precision.inthashCode()Returns a hash code for this apint.booleanReturns if this number has an integer value.booleanisShort()Returns if this apint is "short".Calculates the remainder when divided by an apint.Multiplies two apints.negate()Negative value.Numerator of this aprational.intradix()Radix of this apint.longscale()Returns the scale of this apint.intsignum()Returns the signum function of this apint.longsize()Returns the size of this apint.Subtracts two apints.booleanTests two apfloat numbers for equality.booleanTests two apint numbers for equality.booleantest(Aprational x) Tests two aprational numbers for equality.Converts this apint to Java'sBigInteger.toRadix(int radix) Convert this apint to the specified radix.toString(boolean pretty) Returns a string representation of this aprational.truncate()Truncates fractional part.voidWrite a string representation of this aprational to aWriter.Methods inherited from class org.apfloat.Aprational
add, divide, mod, multiply, precision, preferCompare, subtract, toString, writeToMethods inherited from class org.apfloat.Apfloat
add, byteValue, divide, doubleValue, equalDigits, floatValue, imag, intValue, longValue, longValueExact, mod, multiply, precision, real, shortValue, subtractMethods inherited from class org.apfloat.Apcomplex
add, byteValueExact, conj, divide, equalDigits, intValueExact, isZero, multiply, shortValueExact, subtract, test
-
Constructor Details
-
Apint
protected Apint()Default constructor. To be used only by subclasses that overload all needed methods. -
Apint
Constructs an apfloat from the specified string. The default radix will be used.- Parameters:
value- The string representing the number.- Throws:
NumberFormatException- In case the number is invalid.ApfloatRuntimeException
-
Apint
Constructs an apfloat from the specified string and radix.- Parameters:
value- The string representing the number.radix- The radix of the number.- Throws:
NumberFormatException- In case the number is invalid.ApfloatRuntimeException
-
Apint
Constructs an apfloat from the specifiedlong. The default radix will be used.- Parameters:
value- The value of the number.- Throws:
NumberFormatException- In case the number is invalid.ApfloatRuntimeException
-
Apint
Constructs an apfloat from the specifiedlongand radix.- Parameters:
value- The value of the number.radix- The radix of the number.- Throws:
NumberFormatException- In case the number is invalid.ApfloatRuntimeException
-
Apint
Reads an apint from a stream using the default radix.- Parameters:
in- The stream to read from- Throws:
IOException- If an I/O error occurs accessing the stream.NumberFormatException- If the number is not valid.ApfloatRuntimeException
-
Apint
public Apint(PushbackReader in, int radix) throws IOException, NumberFormatException, ApfloatRuntimeException Reads an apint from a stream using the specified radix.- Parameters:
in- The stream to read fromradix- The radix of the number.- Throws:
IOException- If an I/O error occurs accessing the stream.NumberFormatException- If the number is not valid.ApfloatRuntimeException
-
Apint
Constructs an apint from aBigInteger. The default radix is used.- Parameters:
value- The value of the number.- Throws:
NumberFormatException- If the default radix is not valid.ApfloatRuntimeException
-
Apint
Constructs an apint from aBigIntegerusing the specified radix.- Parameters:
value- The value of the number.radix- The radix of the number.- Throws:
NumberFormatException- If the radix is not valid.ApfloatRuntimeException
-
-
Method Details
-
numerator
Numerator of this aprational.- Overrides:
numeratorin classAprational- Returns:
this.
-
denominator
Denominator of this aprational.- Overrides:
denominatorin classAprational- Returns:
Apcomplex.ONE.
-
radix
public int radix()Radix of this apint.- Overrides:
radixin classAprational- Returns:
- Radix of this apint.
-
scale
Returns the scale of this apint. Scale is equal to the number of digits in an apint.Zero has a scale of
-INFINITE.- Overrides:
scalein classAprational- Returns:
- Number of digits in this apint in the radix in which it's presented.
- Throws:
ApfloatRuntimeException- See Also:
-
size
Returns the size of this apint. Size is equal to the number of significant digits in the number, excluding any trailing zeros.Zero has a size of
0.- Overrides:
sizein classAprational- Returns:
- Number of significant digits in this number, excluding trailing zeros, in the radix in which it's presented.
- Throws:
ApfloatRuntimeException- Since:
- 1.6
- See Also:
-
signum
public int signum()Returns the signum function of this apint.- Overrides:
signumin classAprational- Returns:
- -1, 0 or 1 as the value of this apint is negative, zero or positive.
-
isShort
Returns if this apint is "short".- Overrides:
isShortin classAprational- Returns:
trueif the apint is "short",falseif not.- Throws:
ApfloatRuntimeException- See Also:
-
isInteger
Returns if this number has an integer value.For
Apintthis method always returnstrue.- Overrides:
isIntegerin classAprational- Returns:
true.- Throws:
ApfloatRuntimeException- Since:
- 1.9.0
-
negate
Negative value.- Overrides:
negatein classAprational- Returns:
-this.- Throws:
ApfloatRuntimeException- Since:
- 1.1
-
add
Adds two apints.- Parameters:
x- The number to be added to this number.- Returns:
this + x.- Throws:
ApfloatRuntimeException
-
subtract
Subtracts two apints.- Parameters:
x- The number to be subtracted from this number.- Returns:
this - x.- Throws:
ApfloatRuntimeException
-
multiply
Multiplies two apints.- Parameters:
x- The number to be multiplied by this number.- Returns:
this * x.- Throws:
ApfloatRuntimeException
-
divide
Divides two apints.- Parameters:
x- The number by which this number is to be divided.- Returns:
this / x.- Throws:
ArithmeticException- In case the divisor is zero.ApfloatRuntimeException
-
mod
Calculates the remainder when divided by an apint. The result has the same sign as this number. Ifxis zero, then zero is returned.- Parameters:
x- The number that is used as the divisor in the remainder calculation.- Returns:
this % x.- Throws:
ApfloatRuntimeException- See Also:
-
floor
Floor function. Returns the largest (closest to positive infinity) value that is not greater than this apfloat and is equal to a mathematical integer.- Overrides:
floorin classAprational- Returns:
- This apint.
-
ceil
Ceiling function. Returns the smallest (closest to negative infinity) value that is not less than this apfloat and is equal to a mathematical integer.- Overrides:
ceilin classAprational- Returns:
- This apint.
-
truncate
Truncates fractional part.- Overrides:
truncatein classAprational- Returns:
- This apint.
-
frac
Returns the fractional part.- Overrides:
fracin classAprational- Returns:
- Always zero.
- Throws:
ApfloatRuntimeException- Since:
- 1.7.0
-
toBigInteger
Converts this apint to Java'sBigInteger. This method can be greatly faster than converting to String and then to BigInteger.- Returns:
- This apint converted to a
BigInteger. - Throws:
IllegalArgumentException- If this number is too big to fit in aBigInteger.- Since:
- 1.6
-
toRadix
Convert this apint to the specified radix.- Overrides:
toRadixin classAprational- Parameters:
radix- The radix.- Returns:
- This number in the specified radix.
- Throws:
NumberFormatException- If the radix is invalid.ApfloatRuntimeException- Since:
- 1.2
-
compareTo
Compare this apint to the specified apint.- Parameters:
x- Apint to which this apint is to be compared.- Returns:
- -1, 0 or 1 as this apint is numerically less than, equal to, or greater than
x.
-
compareTo
Compare this apint to the specified aprational.- Overrides:
compareToin classAprational- Parameters:
x- Aprational to which this apint is to be compared.- Returns:
- -1, 0 or 1 as this apint is numerically less than, equal to, or greater than
x.
-
compareTo
Compare this apint to the specified apfloat.- Specified by:
compareToin interfaceComparable<Apfloat>- Overrides:
compareToin classAprational- Parameters:
x- Apfloat to which this apint is to be compared.- Returns:
- -1, 0 or 1 as this apint is numerically less than, equal to, or greater than
x.
-
equals
Compares this object to the specified object.Note: if two apfloats are compared where one number doesn't have enough precise digits, the mantissa is assumed to contain zeros. See
Apfloat.compareTo(Apfloat).- Overrides:
equalsin classAprational- Parameters:
obj- The object to compare with.- Returns:
trueif the objects are the same;falseotherwise.
-
test
Tests two apint numbers for equality. Returnsfalseif the numbers are definitely known to be not equal. Iftrueis returned, equality is unknown and should be verified by callingequals(Object). This method is usually significantly faster than callingequals(Object).- Parameters:
x- The number to test against.- Returns:
falseif the numbers are definitely not equal,trueif unknown.- Since:
- 1.10.0
-
test
Description copied from class:AprationalTests two aprational numbers for equality. Returnsfalseif the numbers are definitely known to be not equal. Iftrueis returned, equality is unknown and should be verified by callingAprational.equals(Object). This method is usually significantly faster than callingequals(Object).- Overrides:
testin classAprational- Parameters:
x- The number to test against.- Returns:
falseif the numbers are definitely not equal,trueif unknown.
-
test
Description copied from class:ApfloatTests two apfloat numbers for equality. Returnsfalseif the numbers are definitely known to be not equal. Iftrueis returned, equality is unknown and should be verified by callingApfloat.equals(Object). This method is usually significantly faster than callingequals(Object).- Overrides:
testin classAprational- Parameters:
x- The number to test against.- Returns:
falseif the numbers are definitely not equal,trueif unknown.
-
hashCode
public int hashCode()Returns a hash code for this apint.- Overrides:
hashCodein classAprational- Returns:
- The hash code value for this object.
-
toString
Returns a string representation of this aprational.- Overrides:
toStringin classAprational- Parameters:
pretty-trueto use a fixed-point notation,falseto use an exponential notation.- Returns:
- A string representing this object.
- Throws:
ApfloatRuntimeException
-
writeTo
Write a string representation of this aprational to aWriter.- Overrides:
writeToin classAprational- Parameters:
out- The outputWriter.pretty-trueto use a fixed-point notation,falseto use an exponential notation.- Throws:
IOException- In case of I/O error writing to the stream.ApfloatRuntimeException
-
formatTo
Description copied from class:AprationalFormats the object using the provided formatter.- Specified by:
formatToin interfaceFormattable- Overrides:
formatToin classAprational- Parameters:
formatter- The formatter.flags- The flags to modify the output format.width- The minimum number of characters to be written to the output, or-1for no minimum.precision- The maximum number of characters to be written to the output, or-1for no maximum.- See Also:
-
getImpl
Returns anApfloatImplrepresenting this apint up to the requested precision.- Overrides:
getImplin classAprational- Parameters:
precision- Precision of theApfloatImplthat is needed.- Returns:
- An
ApfloatImplrepresenting this object to the requested precision. - Throws:
ApfloatRuntimeException
-