-- Collection of code snippets by Arne Vajhøj 
-- (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
with Ada.Text_IO,Ada.Integer_Text_IO;

use Ada.Text_IO,Ada.Integer_Text_IO;

package body Fraction is
    procedure Fraction_Create(O : in Integer; U : in Integer; Instance : out Fraction_Type) is
    
    begin
        Instance.M_O := O;
        Instance.M_U := U;
    end Fraction_Create;
    
    function Over(F : in Fraction_Type) return Integer is
    
    begin
        return F.M_O;
    end Over;
    
    function Under(F : in Fraction_Type) return Integer is
    
    begin
        return F.M_U;
    end Under;
    
    procedure Put(F : in Fraction_Type) is
    
    begin
        Put(F.M_O,Width=>1);
        Put("/");
        Put(F.M_U,Width=>1);
    end Put;
    
    function "+"(F1 : in Fraction_Type; F2 : Fraction_Type) return Fraction_Type is
    
    Res : Fraction_Type;
    
    begin
        Res.M_O := F1.M_O * F2.M_U + F2.M_O * F1.M_U;
        Res.M_U := F1.M_U * F2.M_U;
        return Res;
    end "+";
    
    function "-"(F1 : in Fraction_Type; F2 : Fraction_Type) return Fraction_Type is
    
    Res : Fraction_Type;
    
    begin
        Res.M_O := F1.M_O * F2.M_U - F2.M_O * F1.M_U;
        Res.M_U := F1.M_U * F2.M_U;
        return Res;
    end "-";
    
    function "*"(F1 : in Fraction_Type; F2 : Fraction_Type) return Fraction_Type is
    
    Res : Fraction_Type;
    
    begin
        Res.M_O := F1.M_O * F2.M_O;
        Res.M_U := F1.M_U * F2.M_U;
        return Res;
    end "*";
    
    function "/"(F1 : in Fraction_Type; F2 : Fraction_Type) return Fraction_Type is
    
    Res : Fraction_Type;
    
    begin
        Res.M_O := F1.M_O * F2.M_U;
        Res.M_U := F1.M_U * F2.M_O;
        return Res;
    end "/";
end Fraction;
