java.lang.Cloneable
, java.lang.Comparable<Rational>
public class Rational extends java.lang.Object implements java.lang.Cloneable, java.lang.Comparable<Rational>
Modifier and Type | Field | Description |
---|---|---|
static Rational |
HALF |
The constant 1/2
|
static java.math.BigInteger |
MAX_INT |
The maximum and minimum value of a standard Java integer, 2^31.
|
static java.math.BigInteger |
MIN_INT |
|
static Rational |
ZERO |
The constant 0.
|
Constructor | Description |
---|---|
Rational() |
Default ctor, which represents the zero.
|
Rational(int n) |
ctor from an integer.
|
Rational(int a,
int b) |
ctor from a numerator and denominator.
|
Rational(java.lang.String str) |
ctor from a string representation.
|
Rational(java.lang.String str,
int radix) |
ctor from a string representation in a specified base.
|
Rational(java.math.BigInteger a) |
ctor from a numerator.
|
Rational(java.math.BigInteger a,
java.math.BigInteger b) |
ctor from a numerator and denominator.
|
Modifier and Type | Method | Description |
---|---|---|
Rational |
abs() |
Absolute value.
|
Rational |
add(int val) |
Add another integer.
|
Rational |
add(Rational val) |
Add another fraction.
|
Rational |
add(java.math.BigInteger val) |
Add another integer.
|
java.math.BigDecimal |
BigDecimalValue(java.math.MathContext mc) |
Return a representation as BigDecimal.
|
static Rational |
binomial(Rational n,
int m) |
binomial (n choose m).
|
static Rational |
binomial(Rational n,
java.math.BigInteger m) |
binomial (n choose m).
|
java.math.BigInteger |
ceil() |
ceil(): the nearest integer not smaller than this.
|
Rational |
clone() |
Create a copy.
|
int |
compareTo(Rational val) |
Compares the value of this with another constant.
|
int |
compareTo(java.math.BigInteger val) |
Compares the value of this with another constant.
|
java.math.BigInteger |
denom() |
Get the denominator.
|
Rational |
divide(int val) |
Divide by an integer.
|
Rational |
divide(Rational val) |
Divide by another fraction.
|
Rational |
divide(java.math.BigInteger val) |
Divide by an integer.
|
double |
doubleValue() |
Return a double value representation.
|
float |
floatValue() |
Return a float value representation.
|
java.math.BigInteger |
floor() |
floor(): the nearest integer not greater than this.
|
static Rational |
hankelSymb(Rational n,
int k) |
Hankel's symbol (n,k)
|
boolean |
isBigInteger() |
True if the value is integer.
|
boolean |
isInteger() |
True if the value is integer and in the range of the standard integer.
|
boolean |
isIntegerFrac() |
True if the value is a fraction of two integers in the range of the standard integer.
|
static java.math.BigInteger |
lcmDenom(Rational[] vals) |
Common lcm of the denominators of a set of rational values.
|
Rational |
max(Rational val) |
Compares the value of this with another constant.
|
Rational |
min(Rational val) |
Compares the value of this with another constant.
|
Rational |
multiply(int val) |
Multiply by an integer.
|
Rational |
multiply(Rational val) |
Multiply by another fraction.
|
Rational |
multiply(java.math.BigInteger val) |
Multiply by a BigInteger.
|
Rational |
negate() |
Compute the negative.
|
protected void |
normalize() |
Normalize to coprime numerator and denominator.
|
java.math.BigInteger |
numer() |
Get the numerator.
|
Rational |
Pochhammer(int n) |
Compute pochhammer's symbol (this)_n.
|
Rational |
Pochhammer(java.math.BigInteger n) |
Compute Pochhammer's symbol (this)_n.
|
Rational |
pow(int exponent) |
Power to an integer.
|
Rational |
pow(Rational exponent) |
Raise to a rational power.
|
Rational |
pow(java.math.BigInteger exponent) |
Power to an integer.
|
Rational |
root(java.math.BigInteger r) |
r-th root.
|
int |
signum() |
The sign: 1 if the number is >0, 0 if ==0, -1 if <0
|
Rational |
subtract(int val) |
Subtract an integer.
|
Rational |
subtract(Rational val) |
Subtract another fraction.
|
Rational |
subtract(java.math.BigInteger val) |
Subtract an integer.
|
java.lang.String |
toFString(int digits) |
Return a string in floating point format.
|
java.lang.String |
toString() |
Return a string in the format number/denom.
|
java.math.BigInteger |
trunc() |
Remove the fractional part.
|
public static java.math.BigInteger MAX_INT
public static java.math.BigInteger MIN_INT
public static Rational ZERO
public static Rational HALF
public Rational()
public Rational(java.math.BigInteger a, java.math.BigInteger b)
a
- the numerator.b
- the denominator.public Rational(java.math.BigInteger a)
a
- the BigInteger.public Rational(int a, int b)
a
- the numerator.b
- the denominator.public Rational(int n)
n
- the integer to be represented by the new instance.public Rational(java.lang.String str) throws java.lang.NumberFormatException
str
- the string.
This either has a slash in it, separating two integers, or, if there is no slash,
is representing the numerator with implicit denominator equal to 1.
Warning: this does not yet test for a denominator equal to zerojava.lang.NumberFormatException
public Rational(java.lang.String str, int radix) throws java.lang.NumberFormatException
str
- the string.
This either has a slash in it, separating two integers, or, if there is no slash,
is just representing the numerator.radix
- the number base for numerator and denominator
Warning: this does not yet test for a denominator equal to zerojava.lang.NumberFormatException
public Rational clone()
clone
in class java.lang.Object
public Rational multiply(Rational val)
val
- a second rational number.public Rational multiply(java.math.BigInteger val)
val
- a second number.public Rational multiply(int val)
val
- a second number.public Rational pow(int exponent)
exponent
- the exponent.public Rational pow(java.math.BigInteger exponent) throws java.lang.NumberFormatException
exponent
- the exponent.java.lang.NumberFormatException
public Rational root(java.math.BigInteger r) throws java.lang.NumberFormatException
r
- the inverse of the exponent.
2 for the square root, 3 for the third root etcjava.lang.NumberFormatException
public Rational pow(Rational exponent) throws java.lang.NumberFormatException
exponent
- The exponent.java.lang.NumberFormatException
public Rational divide(Rational val)
val
- A second rational number.public Rational divide(java.math.BigInteger val)
val
- a second number.public Rational divide(int val)
val
- A second number.public Rational add(Rational val)
val
- The number to be addedpublic Rational add(java.math.BigInteger val)
val
- The number to be addedpublic Rational add(int val)
val
- The number to be addedpublic Rational negate()
public Rational subtract(Rational val)
val
- the number to be subtracted from thispublic Rational subtract(java.math.BigInteger val)
val
- the number to be subtracted from thispublic Rational subtract(int val)
val
- the number to be subtracted from thispublic static Rational binomial(Rational n, java.math.BigInteger m)
n
- the numerator. Equals the size of the set to choose from.m
- the denominator. Equals the number of elements to select.public static Rational binomial(Rational n, int m)
n
- the numerator. Equals the size of the set to choose from.m
- the denominator. Equals the number of elements to select.public static Rational hankelSymb(Rational n, int k)
n
- the first parameter.k
- the second parameter, greater or equal to 0.public java.math.BigInteger numer()
public java.math.BigInteger denom()
public Rational abs()
public java.math.BigInteger floor()
public java.math.BigInteger ceil()
public java.math.BigInteger trunc()
public int compareTo(Rational val)
compareTo
in interface java.lang.Comparable<Rational>
val
- the other constant to compare withpublic int compareTo(java.math.BigInteger val)
val
- the other constant to compare withpublic java.lang.String toString()
toString
in class java.lang.Object
public double doubleValue()
public float floatValue()
public java.math.BigDecimal BigDecimalValue(java.math.MathContext mc)
mc
- the mathematical context which determines precision, rounding mode etcpublic java.lang.String toFString(int digits)
digits
- The precision (number of digits)public Rational max(Rational val)
val
- The other constant to compare withpublic Rational min(Rational val)
val
- The other constant to compare withpublic Rational Pochhammer(java.math.BigInteger n)
n
- The number of product terms in the evaluation.public Rational Pochhammer(int n)
n
- The number of product terms in the evaluation.public boolean isBigInteger()
public boolean isInteger()
public boolean isIntegerFrac()
public int signum()
public static java.math.BigInteger lcmDenom(Rational[] vals)
vals
- The list/set of the rational values.protected void normalize()