with Universal_Integer_Arithmetic;
use Universal_Integer_Arithmetic;
package Universal_Real_Arithmetic is

    --  This package implements the Ada type Universal_real.

    --  The operations defined on universal numbers are those specified in
    --  chapter 4 of the RM.  Since the equality and inequality operators can
    --  not be overloaded, an equality function is defined.   A universal real
    --  number corresponds to a unique pair of universal integers that represent
    --  it as a rational number.  A function, UR, is defined that constructs a
    --  universal real number from a pair of universal integers.  Also, the inverse
    --  of this function is provided by two functions, NUMERATOR and DENOMINATOR,
    --  that decompose the rational number representation of their universal real
    --  argument into its numerator and denominator, respectively. In addition,
    --  conversions between Universal_integer and Universal_real are defined.


    type Universal_Real is private;


    function "+" (X, Y : Universal_Real) return Universal_Real;
    function "-" (X, Y : Universal_Real) return Universal_Real;
    function "*" (X, Y : Universal_Real) return Universal_Real;
    function "/" (X, Y : Universal_Real) return Universal_Real;

    function "**" (X : Universal_Real; Y : Integer) return Universal_Real;

    function "*" (X : Universal_Integer; Y : Universal_Real)
                 return Universal_Real;
    function "*" (X : Universal_Real; Y : Universal_Integer)
                 return Universal_Real;
    function "/" (X : Universal_Real; Y : Universal_Integer)
                 return Universal_Real;

    function "-" (X : Universal_Real) return Universal_Real;
    function "abs" (X : Universal_Real) return Universal_Real;

    function ">=" (X, Y : Universal_Real) return Boolean;
    function ">" (X, Y : Universal_Real) return Boolean;
    function "<=" (X, Y : Universal_Real) return Boolean;
    function "<" (X, Y : Universal_Real) return Boolean;
    function Eql (X, Y : Universal_Real) return Boolean;


    function Ui (X : Universal_Real) return Universal_Integer;

    -- Converts a universal real to a universal integer by rounding.


    function Ur (X : Universal_Integer) return Universal_Real;

    -- Converts a universal integer to a universal real.


    function Ur (N, D : Universal_Integer) return Universal_Real;

    -- Constructs a universal real as the ratio of  two universal integers.
    -- The value of d must not be ZERO; if it is, NUMERIC_ERROR is raised.


    function Numerator (X : Universal_Real) return Universal_Integer;

    -- Returns the numerator of x viewed as a rational number.


    function Denominator (X : Universal_Real) return Universal_Integer;

    -- Returns the denominator of x viewed as a rational number.


private

    --  A universal real is represented as a rational number consisting
    --  of a pair of universal integers.  The numerator is the first
    --  member of the pair and the denominator is the second.  The
    --  denominator must not be zero.  Also, the numerator, denominator
    --  pair is always reduced to lowest terms.

    type Universal_Real is
        record
            Num : Universal_Integer;
            Den : Universal_Integer;
        end record;


end Universal_Real_Arithmetic;
