|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Number | +--org.apfloat.Apcomplex | +--org.apfloat.Apfloat | +--org.apfloat.Aprational
Arbitrary precision rational number class. An aprational consists of
a numerator and a denominator of type Apint
.
Apint
,
Serialized FormField Summary |
Fields inherited from class org.apfloat.Apcomplex |
DEFAULT, I, INFINITE, ONE, ZERO |
Constructor Summary | |
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(java.math.BigInteger value)
Constructs an aprational from a BigInteger .
|
|
Aprational(java.math.BigInteger value,
int radix)
Constructs an aprational from a BigInteger using the specified radix. |
|
Aprational(java.io.PushbackReader in)
Reads an aprational from a reader. |
|
Aprational(java.io.PushbackReader in,
int radix)
Reads an aprational from a reader. |
|
Aprational(java.lang.String value)
Constructs an aprational from a string. |
|
Aprational(java.lang.String value,
int radix)
Constructs an aprational from a string with the specified radix. |
Method Summary | |
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. |
int |
compareTo(java.lang.Object obj)
Compare this aprational to the specified object. |
Apint |
denominator()
Denominator of this aprational. |
Aprational |
divide(Aprational x)
Divides two aprational numbers. |
boolean |
equals(java.lang.Object obj)
Compares this object to the specified object. |
Apint |
floor()
Floor function. |
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 |
multiply(Aprational x)
Multiplies two aprational numbers. |
Apint |
numerator()
Numerator of this aprational. |
long |
precision()
Returns the precision of this aprational. |
int |
radix()
Radix of this aprational. |
long |
scale()
Returns the scale of this aprational. |
int |
signum()
Returns the signum function of this aprational. |
Aprational |
subtract(Aprational x)
Subtracts two aprational numbers. |
java.lang.String |
toString()
Returns a string representation of this aprational. |
java.lang.String |
toString(boolean pretty)
Returns a string representation of this aprational. |
Apint |
truncate()
Truncates fractional part. |
void |
writeTo(java.io.Writer out)
Write a string representation of this aprational to a Writer . |
void |
writeTo(java.io.Writer out,
boolean pretty)
Write a string representation of this aprational to a Writer . |
Methods inherited from class org.apfloat.Apfloat |
add, byteValue, divide, doubleValue, equalDigits, floatValue, imag, intValue, longValue, multiply, precision, real, shortValue, subtract |
Methods inherited from class org.apfloat.Apcomplex |
add, conj, divide, equalDigits, multiply, subtract |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
protected Aprational()
public Aprational(Apint value) throws ApfloatRuntimeException
value
- The numerator of the number.public Aprational(Apint numerator, Apint denominator) throws java.lang.IllegalArgumentException, ApfloatRuntimeException
numerator
- The numerator.denominator
- The denominator.
java.lang.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.
ApfloatRuntimeException
public Aprational(java.lang.String value) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
The input must be of one of the formats
integer
numerator [whitespace] "/" [whitespace] denominator
value
- The input string.
java.lang.NumberFormatException
- In case the number is invalid.
java.lang.IllegalArgumentException
- In case the denominator is zero.
ApfloatRuntimeException
public Aprational(java.lang.String value, int radix) throws java.lang.NumberFormatException, java.lang.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.
java.lang.NumberFormatException
- In case the number is invalid.
java.lang.IllegalArgumentException
- In case the denominator is zero.
ApfloatRuntimeException
public Aprational(java.io.PushbackReader in) throws java.io.IOException, java.lang.NumberFormatException, java.lang.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.
java.io.IOException
- In case of I/O error reading the stream.
java.lang.NumberFormatException
- In case the number is invalid.
java.lang.IllegalArgumentException
- In case the denominator is zero.
ApfloatRuntimeException
public Aprational(java.io.PushbackReader in, int radix) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.NumberFormatException, java.lang.IllegalArgumentException, ApfloatRuntimeException
in
- The input stream.radix
- The radix to be used.
java.io.IOException
- In case of I/O error reading the stream.
java.lang.IllegalArgumentException
- In case the denominator is zero.
java.lang.NumberFormatException
- In case the number is invalid.
ApfloatRuntimeException
Aprational(PushbackReader)
public Aprational(java.math.BigInteger value) throws ApfloatRuntimeException
BigInteger
.
The default radix is used.
value
- The numerator of the number.public Aprational(java.math.BigInteger value, int radix) throws ApfloatRuntimeException
BigInteger
using the specified radix.
value
- The numerator of the number.radix
- The radix of the number.Method Detail |
public Apint numerator()
n
where aprational = n / m
.public Apint denominator()
m
where aprational = n / m
.public int radix()
radix
in class Apfloat
public long precision() throws ApfloatRuntimeException
precision
in class Apfloat
INFINITE
ApfloatRuntimeException
public long scale() throws ApfloatRuntimeException
Zero has a scale of -INFINITE
.
scale
in class Apfloat
ApfloatRuntimeException
public int signum()
signum
in class Apfloat
public boolean isShort() throws ApfloatRuntimeException
isShort
in class Apfloat
true
if the aprational is "short", false
if not.
ApfloatRuntimeException
Apfloat.isShort()
public Aprational add(Aprational x) throws ApfloatRuntimeException
x
- The number to be added to this number.
this + x
.
ApfloatRuntimeException
public Aprational subtract(Aprational x) throws ApfloatRuntimeException
x
- The number to be subtracted from this number.
this - x
.
ApfloatRuntimeException
public Aprational multiply(Aprational x) throws ApfloatRuntimeException
x
- The number to be multiplied by this number.
this * x
.
ApfloatRuntimeException
public Aprational divide(Aprational x) throws java.lang.ArithmeticException, ApfloatRuntimeException
x
- The number by which this number is to be divided.
this / x
.
java.lang.ArithmeticException
- In case the divisor is zero.
ApfloatRuntimeException
public Apint floor() throws ApfloatRuntimeException
floor
in class Apfloat
ApfloatRuntimeException
public Apint ceil() throws ApfloatRuntimeException
ceil
in class Apfloat
ApfloatRuntimeException
public Apint truncate() throws ApfloatRuntimeException
truncate
in class Apfloat
ApfloatRuntimeException
public int compareTo(Aprational x) throws ApfloatRuntimeException
x
- Aprational to which this aprational is to be compared.
x
.
ApfloatRuntimeException
public int compareTo(Apfloat x) throws ApfloatRuntimeException
compareTo
in class Apfloat
x
- Apfloat to which this aprational is to be compared.
x
.
ApfloatRuntimeException
public int compareTo(java.lang.Object obj) throws java.lang.ClassCastException
compareTo
in interface java.lang.Comparable
compareTo
in class Apfloat
obj
- Object to which this aprational is to be compared.
obj
.
java.lang.ClassCastException
- If the specified object is not an apfloat.public boolean equals(java.lang.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 Apfloat
obj
- The object to compare with.
true
if the objects are the same; false
otherwise.public int hashCode()
hashCode
in class Apfloat
public java.lang.String toString()
toString
in class Apcomplex
public java.lang.String toString(boolean pretty) throws ApfloatRuntimeException
toString
in class Apfloat
pretty
- true
to use a fixed-point notation, false
to use an exponential notation.
ApfloatRuntimeException
public void writeTo(java.io.Writer out) throws java.io.IOException, ApfloatRuntimeException
Writer
.
writeTo
in class Apcomplex
out
- The output Writer
.
java.io.IOException
- In case of I/O error writing to the stream.
ApfloatRuntimeException
public void writeTo(java.io.Writer out, boolean pretty) throws java.io.IOException, ApfloatRuntimeException
Writer
.
writeTo
in class Apfloat
out
- The output Writer
.pretty
- true
to use a fixed-point notation, false
to use an exponential notation.
java.io.IOException
- In case of I/O error writing to the stream.
ApfloatRuntimeException
protected ApfloatImpl getImpl(long precision) throws ApfloatRuntimeException
ApfloatImpl
representing the approximation of this
aprational up to the requested precision.
getImpl
in class Apfloat
precision
- Precision of the ApfloatImpl
that is needed.
ApfloatImpl
representing this object to the requested precision.
ApfloatRuntimeException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |