public class Fraction
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable, java.io.Serializable
Modifier and Type | Field and Description |
---|---|
protected long |
denominator_ |
protected long |
numerator_ |
Constructor and Description |
---|
Fraction(Fraction f)
Create a fraction with the same value as Fraction f
|
Fraction(long num,
long den)
Create a Fraction equal in value to num / den
|
Modifier and Type | Method and Description |
---|---|
double |
asDouble()
Return the value of the Fraction as a double
|
java.lang.Object |
clone() |
int |
compareTo(long n)
return a number less, equal, or greater than zero
reflecting whether this Fraction is less, equal or greater than n.
|
int |
compareTo(java.lang.Object other)
return a number less, equal, or greater than zero
reflecting whether this Fraction is less, equal or greater than
the value of Fraction other.
|
long |
denominator()
Return the denominator
|
Fraction |
dividedBy(Fraction b)
return a Fraction representing this Fraction divided by b
|
Fraction |
dividedBy(long n)
return a Fraction representing this Fraction divided by n
|
boolean |
equals(long n) |
boolean |
equals(java.lang.Object other) |
static long |
gcd(long a,
long b)
Compute the nonnegative greatest common divisor of a and b.
|
int |
hashCode() |
Fraction |
inverse()
return a Fraction representing 1 / this Fraction
|
Fraction |
minus(Fraction b)
return a Fraction representing this Fraction minus b
|
Fraction |
minus(long n)
return a Fraction representing this Fraction minus n
|
Fraction |
negative()
return a Fraction representing the negated value of this Fraction
|
long |
numerator()
Return the numerator
|
Fraction |
plus(Fraction b)
return a Fraction representing this Fraction plus b
|
Fraction |
plus(long n)
return a Fraction representing this Fraction plus n
|
Fraction |
times(Fraction b)
return a Fraction representing this Fraction times b
|
Fraction |
times(long n)
return a Fraction representing this Fraction times n
|
java.lang.String |
toString() |
protected final long numerator_
protected final long denominator_
public Fraction(long num, long den)
public Fraction(Fraction f)
public final long numerator()
public final long denominator()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object clone()
clone
in class java.lang.Object
public double asDouble()
public static long gcd(long a, long b)
public Fraction negative()
public Fraction inverse()
public Fraction plus(long n)
public Fraction minus(long n)
public Fraction times(long n)
public Fraction dividedBy(Fraction b)
public Fraction dividedBy(long n)
public int compareTo(java.lang.Object other)
compareTo
in interface java.lang.Comparable
public int compareTo(long n)
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public boolean equals(long n)
public int hashCode()
hashCode
in class java.lang.Object