package ratpack_extras is -- VHDL "max" and a "min" function that operate on two rationals. They should the biggest and smallest among the two,correspondingly. constant numer : INTEGER := 0; -- numerator constant denom : INTEGER := 1; -- denominator type rational is array (natural range numer to denom) of integer; -- range -16384 to 16383; constant RAT_ZERO : rational := (0, 1); constant RAT_ONE : rational := (1, 1); function to_rational (a, b : integer) return rational; function int2rat (a : integer) return rational; function numerator (a : rational) return integer; function denominator (a : rational) return integer; function maxi(a,b,c,d:integer) return rational; end ratpack_extras; package body ratpack_extras is function to_rational (a, b : integer) return rational is variable r : rational; begin r(numer) := a; r(denom) := b; return r; end to_rational; function int2rat (a : integer) return rational is variable r : rational; begin r(numer) := a; r(denom) := 1; return r; end int2rat; function numerator (a : rational) return integer is variable n : integer; begin n := a(numer); return n; end numerator; function denominator (a : rational) return integer is variable d : integer; begin d := a(denom); return d; end denominator; function maxi(a,b,c,d:integer) return rational is variable w,x,y,z:integer; variable t1,t2:integer; variable max : rational; begin t1:=w*z; t2:=x*y; if(t1 > t2)then max(w/x,y/z) := w/x; else max(w/x,y/z) := y/z; end if; return max; end maxi; end ratpack_extras;