public class Aprational extends Apfloat
Apint.Apint,
AprationalMath,
Serialized Form| Modifier | Constructor and Description |
|---|---|
protected |
Aprational()
Default constructor.
|
|
Aprational(Apint value)
Construct an integer aprational whose denominator is one.
|
|
Aprational(Apint numerator,
Apint denominator)
Construct an aprational with the specified numerator and denominator.
|
|
Aprational(BigInteger value)
Constructs an aprational from a
BigInteger. |
|
Aprational(BigInteger value,
int radix)
Constructs an aprational from a
BigInteger using the specified radix. |
|
Aprational(PushbackReader in)
Reads an aprational from a reader.
|
|
Aprational(PushbackReader in,
int radix)
Reads an aprational from a reader.
|
|
Aprational(String value)
Constructs an aprational from a string.
|
|
Aprational(String value,
int radix)
Constructs an aprational from a string with the specified radix.
|
| Modifier and Type | Method and Description |
|---|---|
Aprational |
add(Aprational x)
Adds two aprational numbers.
|
Apint |
ceil()
Ceiling function.
|
int |
compareTo(Apfloat x)
Compare this aprational to the specified apfloat.
|
int |
compareTo(Aprational x)
Compare this aprational to the specified aprational.
|
Apint |
denominator()
Denominator of this aprational.
|
Aprational |
divide(Aprational x)
Divides two aprational numbers.
|
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.
|
Aprational |
frac()
Returns the fractional part.
|
protected ApfloatImpl |
getImpl(long precision)
Returns an
ApfloatImpl representing the approximation of this
aprational up to the requested precision. |
int |
hashCode()
Returns a hash code for this aprational.
|
boolean |
isShort()
Returns if this aprational is "short".
|
Aprational |
mod(Aprational x)
Calculates the remainder when divided by an aprational.
|
Aprational |
multiply(Aprational x)
Multiplies two aprational numbers.
|
Aprational |
negate()
Negative value.
|
Apint |
numerator()
Numerator of this aprational.
|
long |
precision()
Returns the precision of this aprational.
|
boolean |
preferCompare(Apfloat x)
Tests if the comparison with
equals and compareTo should be done in the opposite order. |
int |
radix()
Radix of this aprational.
|
long |
scale()
Returns the scale of this aprational.
|
int |
signum()
Returns the signum function of this aprational.
|
long |
size()
Returns the size of this aprational.
|
Aprational |
subtract(Aprational x)
Subtracts two aprational numbers.
|
Aprational |
toRadix(int radix)
Convert this aprational to the specified radix.
|
String |
toString()
Returns a string representation of this aprational.
|
String |
toString(boolean pretty)
Returns a string representation of this aprational.
|
Apint |
truncate()
Truncates fractional part.
|
void |
writeTo(Writer out)
Write a string representation of this aprational to a
Writer. |
void |
writeTo(Writer out,
boolean pretty)
Write a string representation of this aprational to a
Writer. |
add, byteValue, divide, doubleValue, equalDigits, floatValue, imag, intValue, longValue, mod, multiply, precision, real, shortValue, subtractprotected Aprational()
public Aprational(Apint value) throws ApfloatRuntimeException
value - The numerator of the number.ApfloatRuntimeExceptionpublic Aprational(Apint numerator, Apint denominator) throws IllegalArgumentException, ApfloatRuntimeException
numerator - The numerator.denominator - The denominator.IllegalArgumentException - In case the denominator is zero, or if the denominator is not one or the numerator is not zero, and the radix of the numerator and denominator are different.ApfloatRuntimeExceptionpublic Aprational(String value) throws NumberFormatException, IllegalArgumentException, ApfloatRuntimeException
The input must be of one of the formats
integer
numerator [whitespace] "/" [whitespace] denominator
value - The input string.NumberFormatException - In case the number is invalid.IllegalArgumentException - In case the denominator is zero.ApfloatRuntimeExceptionpublic Aprational(String value, int radix) throws NumberFormatException, IllegalArgumentException, ApfloatRuntimeException
The input must be of one of the formats
integer
numerator [whitespace] "/" [whitespace] denominator
value - The input string.radix - The radix to be used.NumberFormatException - In case the number is invalid.IllegalArgumentException - In case the denominator is zero.ApfloatRuntimeExceptionpublic Aprational(PushbackReader in) throws IOException, NumberFormatException, IllegalArgumentException, ApfloatRuntimeException
PushbackReader so that the invalid character can be
returned back to the stream.The input must be of one of the formats
integer [whitespace]
numerator [whitespace] "/" [whitespace] denominator
in - The input stream.IOException - In case of I/O error reading the stream.NumberFormatException - In case the number is invalid.IllegalArgumentException - In case the denominator is zero.ApfloatRuntimeExceptionpublic Aprational(PushbackReader in, int radix) throws IOException, NumberFormatException, IllegalArgumentException, ApfloatRuntimeException
in - The input stream.radix - The radix to be used.IOException - In case of I/O error reading the stream.NumberFormatException - In case the number is invalid.IllegalArgumentException - In case the denominator is zero.ApfloatRuntimeExceptionAprational(PushbackReader)public Aprational(BigInteger value) throws ApfloatRuntimeException
BigInteger.
The default radix is used.value - The numerator of the number.ApfloatRuntimeExceptionpublic Aprational(BigInteger value, int radix) throws ApfloatRuntimeException
BigInteger using the specified radix.value - The numerator of the number.radix - The radix of the number.ApfloatRuntimeExceptionpublic Apint numerator()
n where this = n / m.public Apint denominator()
m where this = n / m.public int radix()
public long precision()
throws ApfloatRuntimeException
precision in class ApfloatINFINITEApfloatRuntimeExceptionpublic long scale()
throws ApfloatRuntimeException
Zero has a scale of -INFINITE.
scale in class ApfloatApfloatRuntimeExceptionApfloat.scale()public long size()
throws ApfloatRuntimeException
INFINITE.
Zero has a size of 0.
size in class ApfloatApfloatRuntimeExceptionApfloat.size()public int signum()
public boolean isShort()
throws ApfloatRuntimeException
isShort in class Apfloattrue if the aprational is "short", false if not.ApfloatRuntimeExceptionApfloat.isShort()public Aprational negate() throws ApfloatRuntimeException
negate in class Apfloat-this.ApfloatRuntimeExceptionpublic Aprational add(Aprational x) throws ApfloatRuntimeException
x - The number to be added to this number.this + x.ApfloatRuntimeExceptionpublic Aprational subtract(Aprational x) throws ApfloatRuntimeException
x - The number to be subtracted from this number.this - x.ApfloatRuntimeExceptionpublic Aprational multiply(Aprational x) throws ApfloatRuntimeException
x - The number to be multiplied by this number.this * x.ApfloatRuntimeExceptionpublic Aprational divide(Aprational x) throws ArithmeticException, ApfloatRuntimeException
x - The number by which this number is to be divided.this / x.ArithmeticException - In case the divisor is zero.ApfloatRuntimeExceptionpublic Aprational mod(Aprational 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.ApfloatRuntimeExceptionpublic Apint floor() throws ApfloatRuntimeException
floor in class ApfloatApfloatRuntimeExceptionpublic Apint ceil() throws ApfloatRuntimeException
ceil in class ApfloatApfloatRuntimeExceptionpublic Apint truncate() throws ApfloatRuntimeException
truncate in class ApfloatApfloatRuntimeExceptionpublic Aprational frac() throws ApfloatRuntimeException
0 <= abs(x.frac()) < 1.
The fractional part has the same sign as the number. For the fractional and integer parts, this always holds:
x = x.truncate() + x.frac()
frac in class ApfloatApfloatRuntimeExceptionpublic Aprational toRadix(int radix) throws NumberFormatException, ApfloatRuntimeException
toRadix in class Apfloatradix - The radix.NumberFormatException - If the radix is invalid.ApfloatRuntimeExceptionpublic int compareTo(Aprational x)
x - Aprational to which this aprational is to be compared.x.public int compareTo(Apfloat x)
compareTo in interface Comparable<Apfloat>compareTo in class Apfloatx - Apfloat to which this aprational is to be compared.x.public boolean preferCompare(Apfloat x)
Apfloatequals and compareTo should be done in the opposite order.Implementations should avoid infinite recursion.
preferCompare in class Apfloatx - The number to compare to.true if this object should invoke x.equals(this) and -x.compareTo(this) instead of comparing normally.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).
public int hashCode()
public String toString()
public String toString(boolean pretty) throws ApfloatRuntimeException
toString in class Apfloatpretty - true to use a fixed-point notation, false to use an exponential notation.ApfloatRuntimeExceptionpublic void writeTo(Writer out) throws IOException, ApfloatRuntimeException
Writer.writeTo in class Apcomplexout - The output Writer.IOException - In case of I/O error writing to the stream.ApfloatRuntimeExceptionpublic void writeTo(Writer out, boolean pretty) throws IOException, ApfloatRuntimeException
Writer.writeTo in class Apfloatout - 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.ApfloatRuntimeExceptionpublic void formatTo(Formatter formatter, int flags, int width, int precision)
formatTo in interface FormattableformatTo in class Apfloatformatter - 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 the approximation of this
aprational up to the requested precision.getImpl in class Apfloatprecision - Precision of the ApfloatImpl that is needed.ApfloatImpl representing this object to the requested precision.ApfloatRuntimeExceptionCopyright © 2024. All rights reserved.