public class Rational extends java.lang.Object implements java.lang.Comparable<Rational>
ONE.div(NEGATIVE_INFINITY).isNegative() = false (no negative ZERO) ZERO.inverse() = POSITIVE_INFINITY POSITIVE_INFINITY.add(finite number) = POSITIVE_INFINITY. POSITIVE_INFINITY.add(NEGATIVE_INFINITY) = NAN ZERO.mul(POSITIVE_INFINITY) = ZERO.mul(NEGATIVE_INFINITY) = NAN number.div(ZERO) = POSITIVE_INFINITY.mul(number.signum()) NAN.isIntegral = POSITIVE_INFINITY.isIntegral = true NAN.floor() = NAN; POSITIVE_INFINITY.floor() = POSITIVE_INFINITY; NAN.frac() = POSITIVE_INFINITY.frac() = ZERO;This class only uses bigintegers if either numerator or denominator does not fit into an int.
Modifier and Type | Field and Description |
---|---|
static Rational |
MONE
The number -1.
|
static Rational |
NAN
Not a number.
|
static Rational |
NEGATIVE_INFINITY
Negative infinity.
|
static Rational |
ONE
The number 1.
|
static Rational |
POSITIVE_INFINITY
Positive infinity.
|
static Rational |
TWO
The number 2.
|
static Rational |
ZERO
The number 0.
|
Modifier and Type | Method and Description |
---|---|
Rational |
abs()
Compute the absolute of this rational.
|
Rational |
add(Rational other)
Return a new rational representing
this + other . |
Rational |
addmul(Rational fac1,
Rational fac2)
Computes
this + (fac1*fac2) . |
Rational |
ceil()
Return a new rational representing the smallest integral rational not
smaller than
this . |
int |
compareTo(Rational o) |
java.math.BigInteger |
denominator()
Get the denominator of this rational.
|
Rational |
div(Rational other)
Return a new rational representing
this / other . |
boolean |
equals(java.lang.Object o) |
Rational |
floor()
Return a new rational representing the biggest integral rational not
bigger than
this . |
Rational |
frac()
Returns the fractional part of the rational, i.e. the
number this.sub(this.floor()).
|
static java.math.BigInteger |
gcd(java.math.BigInteger i1,
java.math.BigInteger i2)
Compute the gcd of two BigInteger.
|
Rational |
gcd(Rational other)
Compute the gcd of two rationals (this and other).
|
int |
hashCode()
Computes a hashcode.
|
Rational |
inverse()
Returns a new rational representing the inverse of
this . |
boolean |
isIntegral()
Check whether this rational represents an integral value.
|
boolean |
isNegative()
Check whether this rational is negative.
|
boolean |
isRational()
Check whether this rational corresponds to a (finite) rational value.
|
Rational |
mul(java.math.BigInteger other)
Return a new rational representing
this * other . |
Rational |
mul(Rational other)
Return a new rational representing
this * other . |
Rational |
negate()
Returns a new rational equal to
-this . |
java.math.BigInteger |
numerator()
Get the numerator of this rational.
|
int |
signum()
Return the sign of this rational.
|
Rational |
sub(Rational other)
Return a new rational representing
this - other . |
Rational |
subdiv(Rational s,
Rational d)
Computes
(this - s) / d . |
Term |
toSMTLIB(de.uni_freiburg.informatik.ultimate.logic.Theory t)
Deprecated.
Use
toTerm(Sort) since this is the type-safe version |
java.lang.String |
toString()
Get a string representation of this number.
|
Term |
toTerm(Sort sort)
Creates a constant term containing this rational.
|
static Rational |
valueOf(java.math.BigInteger bignum,
java.math.BigInteger bigdenom)
Construct a rational from two bigints.
|
static Rational |
valueOf(long newnum,
long newdenom)
Construct a rational from two longs.
|
public static final Rational POSITIVE_INFINITY
public static final Rational NAN
public static final Rational NEGATIVE_INFINITY
public static final Rational ZERO
public static final Rational ONE
public static final Rational MONE
public static final Rational TWO
public static Rational valueOf(java.math.BigInteger bignum, java.math.BigInteger bigdenom)
bignum
- The numerator.bigdenom
- The denominator.public static Rational valueOf(long newnum, long newdenom)
newnum
- The numerator.newdenom
- The denominator.public static java.math.BigInteger gcd(java.math.BigInteger i1, java.math.BigInteger i2)
i1.gcd(i2)
, but it is more efficient for small numbers.i1
- the first big integer.i2
- the second big integer.public Rational add(Rational other)
this + other
.other
- Rational to add.this
and other
.public Rational addmul(Rational fac1, Rational fac2)
this + (fac1*fac2)
.fac1
- one of the factors.fac2
- the other factor.public Rational subdiv(Rational s, Rational d)
(this - s) / d
.s
- the rational to subtract.d
- the divisor.public Rational negate()
-this
.-this
.public Rational sub(Rational other)
this - other
.other
- Rational to subtract.this
and other
.public Rational mul(Rational other)
this * other
.other
- Rational to multiply.this
and other
.public Rational mul(java.math.BigInteger other)
this * other
.other
- big integer to multiply.this
and other
.public Rational div(Rational other)
this / other
.other
- Rational to divide.this
and other
.public Rational gcd(Rational other)
other
- the second rational argument.public Rational inverse()
this
.this
.public boolean isNegative()
true
iff this rational is negative.public int signum()
public int compareTo(Rational o)
compareTo
in interface java.lang.Comparable<Rational>
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public java.math.BigInteger numerator()
public java.math.BigInteger denominator()
public int hashCode()
257 * numerator + denominator
if both fit into an integer and
257 * numerator().hashCode() + denominator().hashCode()
if big
integers are necessary.hashCode
in class java.lang.Object
public java.lang.String toString()
numerator()+ "/" + denominator()
except for
infinity ("inf"
), nan ("nan"
), or minus
infinity ("-inf"
).toString
in class java.lang.Object
public boolean isIntegral()
true
iff value is integral.public Rational floor()
this
.this
.public Rational frac()
this
.public Rational ceil()
this
.this
.public Rational abs()
public Term toTerm(Sort sort)
sort
- the sort of the constant term that should be created.SMTLIBException
- if term is infinite or NaN, if the
sort is not numeric, or if the term is not integral and the sort
is Int.@Deprecated public Term toSMTLIB(de.uni_freiburg.informatik.ultimate.logic.Theory t)
toTerm(Sort)
since this is the type-safe versiont
- Theory to use during conversion.public boolean isRational()