eu.reservoir.monitoring.core
Class Rational

java.lang.Object
  extended by eu.reservoir.monitoring.core.Rational
All Implemented Interfaces:
java.lang.Comparable<Rational>
Direct Known Subclasses:
Timing

public class Rational
extends java.lang.Object
implements java.lang.Comparable<Rational>

Compilation: javac Rational.java Execution: java Rational Immutable ADT for Rational numbers. Invariants ----------- - gcd(num, den) = 1, i.e, the rational number is in reduced form - den >= 1, the denominator is always a positive integer - 0/1 is the unique representation of 0 We employ some tricks to stave of overflow, but if you need arbitrary precision rationals, use BigRational.java.


Constructor Summary
Rational(int numerator, int denominator)
           
 
Method Summary
 int compareTo(Rational b)
           
 int denominator()
           
 Rational div(java.lang.Integer i)
           
 Rational div(Rational b)
           
 boolean equals(java.lang.Object y)
           
 int hashCode()
           
static void main(java.lang.String[] args)
           
static Rational mediant(Rational r, Rational s)
           
 Rational minus(java.lang.Integer i)
           
 Rational minus(Rational b)
           
 Rational multiply(java.lang.Integer i)
           
 Rational multiply(Rational b)
           
 Rational negative()
           
 int numerator()
           
 Rational plus(java.lang.Integer i)
           
 Rational plus(Rational b)
           
 Rational reciprocal()
           
 java.math.BigDecimal toBigDecimal(int scale)
           
 double toDouble()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rational

public Rational(int numerator,
                int denominator)
Method Detail

numerator

public int numerator()

denominator

public int denominator()

plus

public Rational plus(Rational b)

plus

public Rational plus(java.lang.Integer i)

minus

public Rational minus(Rational b)

minus

public Rational minus(java.lang.Integer i)

negative

public Rational negative()

multiply

public Rational multiply(Rational b)

multiply

public Rational multiply(java.lang.Integer i)

div

public Rational div(Rational b)

div

public Rational div(java.lang.Integer i)

reciprocal

public Rational reciprocal()

toDouble

public double toDouble()

toBigDecimal

public java.math.BigDecimal toBigDecimal(int scale)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

compareTo

public int compareTo(Rational b)
Specified by:
compareTo in interface java.lang.Comparable<Rational>

equals

public boolean equals(java.lang.Object y)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

mediant

public static Rational mediant(Rational r,
                               Rational s)

main

public static void main(java.lang.String[] args)


RESERVOIR Monitoring 0.6.4