-------------------------------------------------------------------------------- -- Filename: ratpack_extras_min.vhd -- Purpose : Test bench for ratpack_extras.vhd -- Author : Raghvendra B.L -- company : Green Turtles Technologies Pvt Ltd -- Date : 13-feb-2012 -- Version : 0.1 -- Revision: 0.0.0 -- Initial version. -- License : Copyright (C) 2012 by Raghavendra B.L -- This program is free software. You can redistribute it and/or -- modify it under the terms of the GNU Lesser General Public License, -- either version 3 of the License, or (at your option) any later -- version. See COPYING. --------------------------------------------------------------------------------- package ratpack_extras_min 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 minx(a,b:rational) return rational; end ratpack_extras_min; package body ratpack_extras_min 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 minx(a,b : rational) return rational is variable w,x,y,z:integer; variable r1,r2,r3,r4 : rational; variable t1,t2:integer; variable minv:rational; begin w := numerator(a); x := denominator(a); y := numerator(b); z := denominator(b); t1:=w*z; t2:=x*y; if(t1 < t2)then minv:=a; else minv:=b; end if; return minv; end minx; end ratpack_extras_min;