Package gnu.math
Class RatNum
-
- All Implemented Interfaces:
Serializable
,Comparable
- Direct Known Subclasses:
IntFraction
,IntNum
public abstract class RatNum extends RealNum
The abstract class of rational numbers.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RatNum()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static RatNum
add(RatNum x, RatNum y, int k)
static RatNum
asRatNumOrNull(Object value)
int
classifyFinite()
Check if value is finite, infinite, or NaN.static int
compare(RatNum x, RatNum y)
abstract IntNum
denominator()
static RatNum
divide(RatNum x, RatNum y)
static boolean
equals(RatNum x, RatNum y)
boolean
equals(Object obj)
static RatNum
infinity(int sign)
Return exact "rational" infinity.boolean
isExact()
boolean
isZero()
static RatNum
make(IntNum num, IntNum den)
static RatNum
neg(RatNum x)
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.RatNum
rneg()
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.static RatNum
valueOf(BigDecimal value)
-
Methods inherited from class gnu.math.RealNum
abs, add, add, angle, asBigDecimal, asRealNumOrNull, compareTo, conjugate, cos, div, divide, exp, im, isNegative, isReal, log, max, min, mul, re, sign, sin, sqrt, tan, times, toExactInt, toExactInt, toInexact, toInt, toScaledInt, toScaledInt, toScaledInt, toStringDecimal, toStringScientific, toStringScientific, toStringScientific, toStringScientific, unitQuaternion, unitVector, vectorPart
-
Methods inherited from class gnu.math.Complex
add, addReversed, colatitude, compare, compare, complexPart, divide, divReversed, equals, imMinusOne, imOne, jm, km, longitude, make, make, mulReversed, neg, neg, polar, polar, power, times, toString
-
Methods inherited from class gnu.math.Quaternion
add, compare, divide, doubleImagValue, doubleJmagValue, doubleKmagValue, doubleRealValue, doubleValue, equals, jmMinusOne, jmOne, kmMinusOne, kmOne, longValue, make, make, neg, number, polar, polar, power, times
-
Methods inherited from class gnu.math.Quantity
add, compare, compareReversed, dimensions, divide, imValue, jmValue, kmValue, make, make, make, reValue, times, unit
-
Methods inherited from class gnu.math.Numeric
add, asNumericOrNull, div_inv, floatValue, geq, grt, intValue, mul_ident, sub, toString
-
Methods inherited from class java.lang.Number
byteValue, shortValue
-
-
-
-
Field Detail
-
ten_exp_9
public static final IntNum ten_exp_9
-
-
Method Detail
-
numerator
public abstract IntNum numerator()
-
denominator
public abstract IntNum denominator()
-
classifyFinite
public int classifyFinite()
Description copied from class:Complex
Check if value is finite, infinite, or NaN.- Overrides:
classifyFinite
in classRealNum
- Returns:
- 1 if finite; 0 if infinite; -1 if NaN.
-
valueOf
public static RatNum valueOf(BigDecimal value)
-
infinity
public static RatNum infinity(int sign)
Return exact "rational" infinity.- Parameters:
sign
- either 1 or -1 for positive or negative infinity
-
power
public Numeric power(IntNum y)
Description copied from class:Numeric
Return this raised to an integer power. Implemented by repeated squaring and multiplication. Ify < 0
, returns div_inv of the result.
-
toExact
public final RatNum toExact()
Description copied from class:RealNum
Convert to an exact number. Implements the Schemeinexact->exact
(for real numbers).
-
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.
-
toExactInt
public IntNum toExactInt(int rounding_mode)
Description copied from class:RealNum
Converts to an exact integer, with specified rounding mode.- Overrides:
toExactInt
in classRealNum
-
-