public class RationalNumber
extends java.lang.Object
| Constructor and Description |
|---|
RationalNumber(double d)
create a rationalNumber that is very close to d.
|
RationalNumber(int n)
create a rationalNumber with n * 10^exp
|
RationalNumber(int n,
int d)
create a new rational number with numerator n and denominator d.
|
RationalNumber(Ratio n)
create a rationalNumber with n * 10^exp
|
RationalNumber(Ratio n,
Ratio exp)
create a rationalNumber with n * 10^exp
|
| Modifier and Type | Method and Description |
|---|---|
RationalNumber |
divide(RationalNumber number)
divide by the number.
|
double |
doubleValue()
return a close representation using double.
|
boolean |
isOne()
return true if the number is 1.
|
boolean |
isZero()
return true if the number is 0.
|
RationalNumber |
multiply(RationalNumber number)
multiply by the number
|
static RationalNumber |
parse(java.lang.String s)
parse the string to get the RationalNumber.
|
RationalNumber |
pow(Ratio r) |
RationalNumber |
sqrt()
returns the sqrt of the number, e.g.
|
java.lang.String |
toString() |
public RationalNumber(double d)
d - public RationalNumber(Ratio n, Ratio exp)
n - exp - public RationalNumber(Ratio n)
n - public RationalNumber(int n)
n - public RationalNumber(int n,
int d)
n - the numeratord - the denominator.public double doubleValue()
public java.lang.String toString()
toString in class java.lang.Objectpublic static RationalNumber parse(java.lang.String s) throws java.lang.NumberFormatException
s - the string.java.lang.NumberFormatExceptionpublic RationalNumber divide(RationalNumber number)
number - public RationalNumber multiply(RationalNumber number)
number - public RationalNumber pow(Ratio r)
public RationalNumber sqrt()
public boolean isOne()
public boolean isZero()