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 alongnumerator andlongdenominator. 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 intcompareTo(Rational pOther)longdenominator()Rationaldivides(Rational pOther)doubledoubleValue()booleanequals(java.lang.Object pOther)floatfloatValue()inthashCode()intintValue()longlongValue()Rationalminus(Rational pOther)Rationalnegate()longnumerator()Rationalplus(Rational pOther)Rationalreciprocal()Rationaltimes(Rational pOther)java.lang.StringtoString()
-
-
-
Method Detail
-
numerator
public long numerator()
-
denominator
public long denominator()
-
intValue
public int intValue()
- Specified by:
intValuein classjava.lang.Number
-
longValue
public long longValue()
- Specified by:
longValuein classjava.lang.Number
-
floatValue
public float floatValue()
- Specified by:
floatValuein classjava.lang.Number
-
doubleValue
public double doubleValue()
- Specified by:
doubleValuein classjava.lang.Number
-
compareTo
public int compareTo(Rational pOther)
- Specified by:
compareToin interfacejava.lang.Comparable<Rational>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object pOther)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
negate
public Rational negate()
-
reciprocal
public Rational reciprocal()
-
-