public class Apint extends Aprational
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()
.
ApintMath
,
Serialized FormModifier | Constructor and Description |
---|---|
protected |
Apint()
Default constructor.
|
|
Apint(BigInteger value)
Constructs an apint from a
BigInteger . |
|
Apint(BigInteger value,
int radix)
Constructs an apint from a
BigInteger using the specified radix. |
|
Apint(long value)
Constructs an apfloat from the specified
long . |
|
Apint(long value,
int radix)
Constructs an apfloat from the specified
long
and 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.
|
|
Apint(String value)
Constructs an apfloat from the specified string.
|
|
Apint(String value,
int radix)
Constructs an apfloat from the specified string and radix.
|
Modifier and Type | Method and Description |
---|---|
Apint |
add(Apint x)
Adds two apints.
|
Apint |
ceil()
Ceiling function.
|
int |
compareTo(Apfloat x)
Compare this apint to the specified apfloat.
|
int |
compareTo(Apint x)
Compare this apint to the specified apint.
|
int |
compareTo(Aprational x)
Compare this apint to the specified aprational.
|
Apint |
denominator()
Denominator of this aprational.
|
Apint |
divide(Apint x)
Divides two apints.
|
boolean |
equals(Object obj)
Compares this object to the specified object.
|
Apint |
floor()
Floor function.
|
void |
formatTo(Formatter formatter,
int flags,
int width,
int precision)
Formats the object using the provided formatter.
|
Apint |
frac()
Returns the fractional part.
|
protected ApfloatImpl |
getImpl(long precision)
Returns an
ApfloatImpl representing this apint up to the requested precision. |
int |
hashCode()
Returns a hash code for this apint.
|
boolean |
isShort()
Returns if this apint is "short".
|
Apint |
mod(Apint x)
Calculates the remainder when divided by an apint.
|
Apint |
multiply(Apint x)
Multiplies two apints.
|
Apint |
negate()
Negative value.
|
Apint |
numerator()
Numerator of this aprational.
|
int |
radix()
Radix of this apint.
|
long |
scale()
Returns the scale of this apint.
|
int |
signum()
Returns the signum function of this apint.
|
long |
size()
Returns the size of this apint.
|
Apint |
subtract(Apint x)
Subtracts two apints.
|
BigInteger |
toBigInteger()
Converts this apint to Java's
BigInteger . |
Apint |
toRadix(int radix)
Convert this apint to the specified radix.
|
String |
toString(boolean pretty)
Returns a string representation of this aprational.
|
Apint |
truncate()
Truncates fractional part.
|
void |
writeTo(Writer out,
boolean pretty)
Write a string representation of this aprational to a
Writer . |
add, divide, mod, multiply, precision, preferCompare, subtract, toString, writeTo
add, byteValue, divide, doubleValue, equalDigits, floatValue, imag, intValue, longValue, mod, multiply, precision, real, shortValue, subtract
protected Apint()
public Apint(String value) throws NumberFormatException, ApfloatRuntimeException
value
- The string representing the number.NumberFormatException
- In case the number is invalid.ApfloatRuntimeException
public Apint(String value, int radix) throws NumberFormatException, ApfloatRuntimeException
value
- The string representing the number.radix
- The radix of the number.NumberFormatException
- In case the number is invalid.ApfloatRuntimeException
public Apint(long value) throws NumberFormatException, ApfloatRuntimeException
long
.
The default radix will be used.value
- The value of the number.NumberFormatException
- In case the number is invalid.ApfloatRuntimeException
public Apint(long value, int radix) throws NumberFormatException, ApfloatRuntimeException
long
and radix.value
- The value of the number.radix
- The radix of the number.NumberFormatException
- In case the number is invalid.ApfloatRuntimeException
public Apint(PushbackReader in) throws IOException, NumberFormatException, ApfloatRuntimeException
in
- The stream to read fromIOException
- If an I/O error occurs accessing the stream.NumberFormatException
- If the number is not valid.ApfloatRuntimeException
public Apint(PushbackReader in, int radix) throws IOException, NumberFormatException, ApfloatRuntimeException
in
- The stream to read fromradix
- The radix of the number.IOException
- If an I/O error occurs accessing the stream.NumberFormatException
- If the number is not valid.ApfloatRuntimeException
public Apint(BigInteger value) throws NumberFormatException, ApfloatRuntimeException
BigInteger
. The default radix is used.value
- The value of the number.NumberFormatException
- If the default radix is not valid.ApfloatRuntimeException
public Apint(BigInteger value, int radix) throws NumberFormatException, ApfloatRuntimeException
BigInteger
using the specified radix.value
- The value of the number.radix
- The radix of the number.NumberFormatException
- If the radix is not valid.ApfloatRuntimeException
public Apint numerator()
numerator
in class Aprational
this
.public Apint denominator()
denominator
in class Aprational
Apcomplex.ONE
.public int radix()
radix
in class Aprational
public long scale() throws ApfloatRuntimeException
Zero has a scale of -INFINITE
.
scale
in class Aprational
ApfloatRuntimeException
Apfloat.scale()
public long size() throws ApfloatRuntimeException
Zero has a size of 0
.
size
in class Aprational
ApfloatRuntimeException
Apfloat.size()
public int signum()
signum
in class Aprational
public boolean isShort() throws ApfloatRuntimeException
isShort
in class Aprational
true
if the apint is "short", false
if not.ApfloatRuntimeException
Apfloat.isShort()
public Apint negate() throws ApfloatRuntimeException
negate
in class Aprational
-this
.ApfloatRuntimeException
public Apint add(Apint x) throws ApfloatRuntimeException
x
- The number to be added to this number.this + x
.ApfloatRuntimeException
public Apint subtract(Apint x) throws ApfloatRuntimeException
x
- The number to be subtracted from this number.this - x
.ApfloatRuntimeException
public Apint multiply(Apint x) throws ApfloatRuntimeException
x
- The number to be multiplied by this number.this * x
.ApfloatRuntimeException
public Apint divide(Apint x) throws ArithmeticException, ApfloatRuntimeException
x
- The number by which this number is to be divided.this / x
.ArithmeticException
- In case the divisor is zero.ApfloatRuntimeException
public Apint mod(Apint x) throws ApfloatRuntimeException
x
is zero, then zero is returned.x
- The number that is used as the divisor in the remainder calculation.this % x
.ApfloatRuntimeException
ApfloatMath.fmod(Apfloat,Apfloat)
public Apint floor()
floor
in class Aprational
public Apint ceil()
ceil
in class Aprational
public Apint truncate()
truncate
in class Aprational
public Apint frac() throws ApfloatRuntimeException
frac
in class Aprational
ApfloatRuntimeException
public BigInteger toBigInteger() throws IllegalArgumentException
BigInteger
.
This method can be greatly faster than converting to String
and then to BigInteger.BigInteger
.IllegalArgumentException
- If this number is too big to fit in a BigInteger
.public Apint toRadix(int radix) throws NumberFormatException, ApfloatRuntimeException
toRadix
in class Aprational
radix
- The radix.NumberFormatException
- If the radix is invalid.ApfloatRuntimeException
public int compareTo(Apint x)
x
- Apint to which this apint is to be compared.x
.public int compareTo(Aprational x)
compareTo
in class Aprational
x
- Aprational to which this apint is to be compared.x
.public int compareTo(Apfloat x)
compareTo
in interface Comparable<Apfloat>
compareTo
in class Aprational
x
- Apfloat to which this apint is to be compared.x
.public boolean equals(Object obj)
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)
.
equals
in class Aprational
obj
- The object to compare with.true
if the objects are the same; false
otherwise.public int hashCode()
hashCode
in class Aprational
public String toString(boolean pretty) throws ApfloatRuntimeException
toString
in class Aprational
pretty
- true
to use a fixed-point notation, false
to use an exponential notation.ApfloatRuntimeException
public void writeTo(Writer out, boolean pretty) throws IOException, ApfloatRuntimeException
Writer
.writeTo
in class Aprational
out
- The output Writer
.pretty
- true
to use a fixed-point notation, false
to use an exponential notation.IOException
- In case of I/O error writing to the stream.ApfloatRuntimeException
public void formatTo(Formatter formatter, int flags, int width, int precision)
Aprational
formatTo
in interface Formattable
formatTo
in class Aprational
formatter
- The formatter.flags
- The flags to modify the output format.width
- The minimum number of characters to be written to the output, or -1
for no minimum.precision
- The maximum number of characters to be written to the output, or -1
for no maximum.Apfloat.formatTo(Formatter,int,int,int)
protected ApfloatImpl getImpl(long precision) throws ApfloatRuntimeException
ApfloatImpl
representing this apint up to the requested precision.getImpl
in class Aprational
precision
- Precision of the ApfloatImpl
that is needed.ApfloatImpl
representing this object to the requested precision.ApfloatRuntimeException
Copyright © 2019. All rights reserved.