|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.ObjectFraction
class Fraction
This class introduces fractions and enables basic operations with them.
| Field Summary | |
|---|---|
(package private) long |
d
the denominator |
(package private) long |
n
the numerator |
| Constructor Summary | |
|---|---|
Fraction()
Constructs a fraction 0/1, ie. zero. |
|
Fraction(double r)
Constructs an estimate fraction from a real number. |
|
Fraction(long nn)
Constructs a fraction from an integer. |
|
Fraction(long nn,
long dd)
Constructs a fraction from its numerator and denominator. |
|
| Method Summary | |
|---|---|
(package private) Fraction |
abs()
Absolute value of the fraction. |
(package private) Fraction |
add(Fraction a)
Adds another fraction to this fraction. |
(package private) int |
compare(Fraction c)
Compares this fraction to another fraction. |
(package private) int |
compare(long c)
Compares this fraction with an integer. |
(package private) SquareRootFraction |
convertToSRF()
Converts this fraction to a SquareRootFraction. |
(package private) Fraction |
divide(Fraction d)
Divides this fraction by another fraction. |
(package private) boolean |
isEqual(Fraction c)
Checks if this fraction is equal to another fraction. |
(package private) boolean |
isEqual(int c)
Checks if this fraction is equal to an integer. |
(package private) Fraction |
multiply(Fraction f)
Multiplies this fraction by another fraction. |
(package private) Fraction |
multiply(long f)
Multiplies this fraction by an integer. |
(package private) Fraction |
squared()
Squares this fraction. |
(package private) Fraction |
subtract(Fraction s)
Subtracts another fraction from this fraction. |
(package private) String |
toTeX()
Prints this fraction formatted as TeX code. |
(package private) String |
toText()
Prints this fraction formatted as text. |
| Methods inherited from class |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
long d
long n
| Constructor Detail |
|---|
Fraction()
Fraction(double r)
Fraction, even if the real
number is an irrational number - the resulting fraction should be correct at least to 10 decimal places. For example, for π, we'll obtain 80143857/25510582.
In any case, the number we obtain should be the best approximation in the sense that there is no better approximation with an equal or lower denominator.
r - the real numberFraction(long nn)
nn - the integer (constructs fraction nn/1)
Fraction(long nn,
long dd)
nn - nominatordd - denominator
IllegalArgumentException - Throws an exception if the denominator would be zero.| Method Detail |
|---|
Fraction abs()
Fraction add(Fraction a)
a - addend
int compare(Fraction c)
c - comparand
int compare(long c)
c - comparand
SquareRootFraction convertToSRF()
SquareRootFraction. Basically this is just re-typing, numerical value will be preserved.
SquareRootFractionFraction divide(Fraction d)
d - divisor
ArithmeticException - Throws an exception if the nominator of the divisor is zero.boolean isEqual(Fraction c)
c - comparand
boolean isEqual(int c)
c - comparand
Fraction multiply(Fraction f)
f - factor
Fraction multiply(long f)
f - factor
Fraction squared()
Fraction subtract(Fraction s)
s - subtrahend
String toTeX()
-\frac{3}{2}String toText()
-3/2
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||