gnu.math
Class RatNum
java.lang.Object
java.lang.Number
gnu.math.Numeric
gnu.math.Quantity
gnu.math.Complex
gnu.math.RealNum
gnu.math.RatNum
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Comparable
- Direct Known Subclasses:
- IntFraction, IntNum
public abstract class RatNum
- extends RealNum
The abstract class of rational numbers.
- See Also:
- Serialized Form
Method Summary |
static RatNum |
add(RatNum x,
RatNum y,
int k)
|
static int |
compare(RatNum x,
RatNum y)
|
abstract IntNum |
denominator()
|
static RatNum |
divide(RatNum x,
RatNum y)
|
boolean |
equals(java.lang.Object obj)
|
static boolean |
equals(RatNum x,
RatNum y)
|
static RatNum |
infinity(int sign)
Return exact "rational" infinity. |
boolean |
isExact()
|
boolean |
isZero()
|
static RatNum |
make(IntNum num,
IntNum den)
|
abstract IntNum |
numerator()
|
Numeric |
power(IntNum y)
Return this raised to an integer power. |
static RealNum |
rationalize(RealNum x,
RealNum y)
Calcaulte the simplest rational between two reals. |
static RatNum |
times(RatNum x,
RatNum y)
|
RatNum |
toExact()
Convert to an exact number. |
IntNum |
toExactInt(int rounding_mode)
Converts to an exact integer, with specified rounding mode. |
RealNum |
toInt(int rounding_mode)
Converts a real to an integer, according to a specified rounding mode. |
Methods inherited from class gnu.math.RealNum |
abs, add, add, compareTo, div, divide, exp, im, isNegative, log, max, min, mul, re, rneg, sign, sin, sqrt, times, toExactInt, toExactInt, toInt, toScaledInt, toScaledInt, toScaledInt |
Methods inherited from class gnu.math.Complex |
add, addReversed, angle, compare, compare, divide, divReversed, doubleImagValue, doubleRealValue, doubleValue, equals, imMinusOne, imOne, longValue, make, make, mulReversed, neg, neg, number, polar, polar, power, times, toString |
Methods inherited from class gnu.math.Quantity |
add, compare, compareReversed, dimensions, divide, imValue, make, make, make, reValue, times, unit |
Methods inherited from class java.lang.Number |
byteValue, shortValue |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
RatNum
public RatNum()
numerator
public abstract IntNum numerator()
denominator
public abstract IntNum denominator()
make
public static RatNum make(IntNum num,
IntNum den)
isExact
public boolean isExact()
- Overrides:
isExact
in class Complex
isZero
public boolean isZero()
- Overrides:
isZero
in class RealNum
infinity
public static RatNum infinity(int sign)
- Return exact "rational" infinity.
- Parameters:
sign
- either 1 or -1 for positive or negative infinity
compare
public static int compare(RatNum x,
RatNum y)
equals
public static boolean equals(RatNum x,
RatNum y)
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in class Complex
add
public static RatNum add(RatNum x,
RatNum y,
int k)
times
public static RatNum times(RatNum x,
RatNum y)
divide
public static RatNum divide(RatNum x,
RatNum y)
power
public Numeric power(IntNum y)
- Description copied from class:
Numeric
- Return this raised to an integer power.
Implemented by repeated squaring and multiplication.
If y < 0, returns div_inv of the result.
- Overrides:
power
in class Numeric
toExact
public final RatNum toExact()
- Description copied from class:
RealNum
- Convert to an exact number.
Implements the Scheme inexact->exact (for real numbers).
- Overrides:
toExact
in class RealNum
toInt
public RealNum toInt(int rounding_mode)
- Description copied from class:
RealNum
- Converts a real to an integer, according to a specified rounding mode.
Note an inexact argument gives an inexact result, following Scheme.
See also toExactInt.
- Overrides:
toInt
in class RealNum
toExactInt
public IntNum toExactInt(int rounding_mode)
- Description copied from class:
RealNum
- Converts to an exact integer, with specified rounding mode.
- Overrides:
toExactInt
in class RealNum
rationalize
public static RealNum rationalize(RealNum x,
RealNum y)
- Calcaulte the simplest rational between two reals.