Class Rational
- java.lang.Object
-
- java.lang.Number
-
- com.twelvemonkeys.imageio.metadata.tiff.Rational
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<Rational>
public final class Rational extends java.lang.Number implements java.lang.Comparable<Rational>
Represents a rational number with along
numerator andlong
denominator. Rational numbers are stored in reduced form with the sign stored with the numerator. Rationals are immutable.Adapted from sample code featured in "Intro to Programming in Java: An Interdisciplinary Approach" (Addison Wesley) by Robert Sedgewick and Kevin Wayne. Permission granted to redistribute under BSD license.
- Version:
- $Id: Rational.java,v 1.0 Nov 18, 2009 1:12:00 AM haraldk Exp$
- Author:
- Harald Kuhr, Robert Sedgewick and Kevin Wayne (original version), last modified by $Author: haraldk$
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(Rational pOther)
long
denominator()
Rational
divides(Rational pOther)
double
doubleValue()
boolean
equals(java.lang.Object pOther)
float
floatValue()
int
hashCode()
int
intValue()
long
longValue()
Rational
minus(Rational pOther)
Rational
negate()
long
numerator()
Rational
plus(Rational pOther)
Rational
reciprocal()
Rational
times(Rational pOther)
java.lang.String
toString()
-
-
-
Method Detail
-
numerator
public long numerator()
-
denominator
public long denominator()
-
intValue
public int intValue()
- Specified by:
intValue
in classjava.lang.Number
-
longValue
public long longValue()
- Specified by:
longValue
in classjava.lang.Number
-
floatValue
public float floatValue()
- Specified by:
floatValue
in classjava.lang.Number
-
doubleValue
public double doubleValue()
- Specified by:
doubleValue
in classjava.lang.Number
-
compareTo
public int compareTo(Rational pOther)
- Specified by:
compareTo
in interfacejava.lang.Comparable<Rational>
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object pOther)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
negate
public Rational negate()
-
reciprocal
public Rational reciprocal()
-
-