package Rationals is
------------------------------------------------------------------
--|                                                              
--| Specification of the abstract data type for representing
--| and manipulating rational numbers.
--| All rational quantities in this package are initialized
--| to 0/1.
--|                                                              
--| Author: Michael B. Feldman, The George Washington University 
--| Last Modified: July 1995                                     
--|                                                              
------------------------------------------------------------------
 
  type Rational is private;

  ZeroDenominator: exception;

  function "/" (X : Integer; Y : Integer) return Rational;
  -- constructor:
  -- Pre :   X and Y are defined
  -- Post:   returns a rational number
  --   If Y > 0, returns Reduce(X,Y)
  --   If Y < 0, returns Reduce(-X,-Y)
  -- Raises: ZeroDenominator if Y = 0
 
  function Numer (R : Rational) return Integer;
  function Denom (R : Rational) return Positive;
  -- selectors:
  -- Pre: R is defined
  -- Post: Numer returns the numerator of R; Denom returns the denominator
 
  function "<" (R1 : Rational; R2 : Rational) return Boolean;
  function "<="(R1 : Rational; R2 : Rational) return Boolean;
  function ">" (R1 : Rational; R2 : Rational) return Boolean;
  function ">="(R1 : Rational; R2 : Rational) return Boolean;
  -- inquiry operators: comparison of two rational numbers
  -- Pre : R1 and R2 are defined
  -- Post: return R1 < R2, R1 > R2, R1 <= R2, and R1 >= R2, respectively
 
  function "+"(R: Rational)   return Rational;
  function "-"(R: Rational)   return Rational;
  function "abs"(R: Rational) return Rational;
  -- monadic arithmetic constructors:
  -- Pre:  R is defined
  -- Post: return R, -R, and ABS R, respectively
 
  function "+"(R1 : Rational; R2 : Rational) return Rational;
  function "-"(R1 : Rational; R2 : Rational) return Rational;
  function "*"(R1 : Rational; R2 : Rational) return Rational;
  function "/"(R1 : Rational; R2 : Rational) return Rational;
  -- dyadic arithmetic constructors:
  -- Pre : R1 and R2 are defined
  -- Post: return the rational sum, difference, product, and
  --   quotient of R1 and R2, respectively
 
private
-- A record of type Rational consists of a pair of Integer values
-- such that the first number represents the numerator of a rational
-- number and the second number represents the denominator.
 
  type Rational is record
    Numerator  : Integer  := 0;
    Denominator: Positive := 1;
  end record; 
end Rationals;