public class RationalNumber
extends java.lang.Object
implements java.io.Serializable
Instances of this class are immutable.
| Modifier and Type | Field and Description |
|---|---|
static RationalNumber |
ONE
One as a rational numer.
|
static RationalNumber |
ZERO
Zero as a rational numer.
|
| Constructor and Description |
|---|
RationalNumber()
Simple constructor.
|
RationalNumber(java.math.BigInteger i)
Simple constructor.
|
RationalNumber(java.math.BigInteger numerator,
java.math.BigInteger denominator)
Simple constructor.
|
RationalNumber(long l)
Simple constructor.
|
RationalNumber(long numerator,
long denominator)
Simple constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static RationalNumber |
abs(RationalNumber r)
Get the absolute value of a rational number.
|
RationalNumber |
add(java.math.BigInteger l)
Add an integer to the instance.
|
RationalNumber |
add(long l)
Add an integer to the instance.
|
RationalNumber |
add(RationalNumber r)
Add a rational number to the instance.
|
RationalNumber |
divide(java.math.BigInteger l)
Divide the instance by an integer.
|
RationalNumber |
divide(long l)
Divide the instance by an integer.
|
RationalNumber |
divide(RationalNumber r)
Divide the instance by a rational number.
|
double |
doubleValue()
Return the
double value of the instance. |
boolean |
equals(java.lang.Object o)
Check if the instance is equal to another rational number.
|
java.math.BigInteger |
getDenominator()
Get the denominator.
|
java.math.BigInteger |
getNumerator()
Get the numerator.
|
int |
hashCode()
Returns a hash code value for the object.
|
RationalNumber |
invert()
Invert the instance.
|
boolean |
isInteger()
Check if the number is integer.
|
boolean |
isNegative()
Check if the number is negative.
|
boolean |
isOne()
Check if the number is one.
|
boolean |
isZero()
Check if the number is zero.
|
RationalNumber |
multiply(java.math.BigInteger l)
Multiply the instance by an integer.
|
RationalNumber |
multiply(long l)
Multiply the instance by an integer.
|
RationalNumber |
multiply(RationalNumber r)
Multiply the instance by a rational number.
|
RationalNumber |
negate()
Negate the instance.
|
RationalNumber |
subtract(java.math.BigInteger l)
Subtract an integer from the instance.
|
RationalNumber |
subtract(long l)
Subtract an integer from the instance.
|
RationalNumber |
subtract(RationalNumber r)
Subtract a rational number from the instance.
|
java.lang.String |
toString()
Returns a string representation of the rational number.
|
public static final RationalNumber ZERO
public static final RationalNumber ONE
public RationalNumber()
public RationalNumber(long numerator,
long denominator)
numerator - numerator of the rational numberdenominator - denominator of the rational numberjava.lang.ArithmeticException - if the denominator is zeropublic RationalNumber(java.math.BigInteger numerator,
java.math.BigInteger denominator)
numerator - numerator of the rational numberdenominator - denominator of the rational numberjava.lang.ArithmeticException - if the denominator is zeropublic RationalNumber(long l)
l - value of the rational numberpublic RationalNumber(java.math.BigInteger i)
i - value of the rational numberpublic RationalNumber negate()
public RationalNumber add(long l)
l - integer to addpublic RationalNumber add(java.math.BigInteger l)
l - integer to addpublic RationalNumber add(RationalNumber r)
r - rational number to addpublic RationalNumber subtract(long l)
l - integer to subtractpublic RationalNumber subtract(java.math.BigInteger l)
l - integer to subtractpublic RationalNumber subtract(RationalNumber r)
r - rational number to subtractpublic RationalNumber multiply(long l)
l - integer to multiply bypublic RationalNumber multiply(java.math.BigInteger l)
l - integer to multiply bypublic RationalNumber multiply(RationalNumber r)
r - rational number to multiply the instance withpublic RationalNumber divide(long l)
l - integer to divide byjava.lang.ArithmeticException - if l is zeropublic RationalNumber divide(java.math.BigInteger l)
l - integer to divide byjava.lang.ArithmeticException - if l is zeropublic RationalNumber divide(RationalNumber r)
r - rational number to divide byjava.lang.ArithmeticException - if r is zeropublic RationalNumber invert()
java.lang.ArithmeticException - if the instance is zeropublic java.math.BigInteger getNumerator()
public java.math.BigInteger getDenominator()
public boolean isZero()
public boolean isOne()
public boolean isInteger()
public boolean isNegative()
public static RationalNumber abs(RationalNumber r)
r - rational number from which we want the absolute valuepublic double doubleValue()
double value of the instance.public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2001-2007 Luc Maisonobe. All Rights Reserved.