----------------------- --------------------------------------------------------- ------------------------------------------------------------------------------ -- Cheddar is a GNU GPL real time scheduling analysis tool. -- This program provides services to automatically check performances -- of real time architectures. -- -- Copyright (C) 2002-2010, by Frank Singhoff, Alain Plantec, Jerome Legrand -- -- The Cheddar project was started in 2002 by -- the LISyC Team, University of Western Britanny. -- -- Since 2008, Ellidiss technologies also contributes to the development of -- Cheddar and provides industrial support. -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- -- -- Contact : cheddar@listes.univ-brest.fr -- ----------------------------------------------------------------------------- -- Last update : -- $Rev: 523 $ -- $Date: 2012-09-26 14:09:39 +0100 (Wed, 26 Sep 2012) $ -- $Author: fotsing $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Text_IO; use Text_IO; package body discrete_util is package integer_io is new Text_IO.Integer_IO (discrete_element); function format (f : in discrete_element) return Unbounded_String is s : String (1 .. 10000); result : Unbounded_String; begin integer_io.Put (s, f, 10); -- Suppress blank -- for i in 1 .. s'Length loop if s (i) /= ' ' then Append (result, s (i)); end if; end loop; return (result); end format; function gcd (left : discrete_element; right : discrete_element) return discrete_element is min : discrete_element := discrete_element'Min (left, right); max : discrete_element := discrete_element'Max (left, right); remainder : discrete_element; begin reduce : loop if min <= 0 then return max; end if; remainder := max rem min; max := min; min := remainder; end loop reduce; end gcd; function lcm (a : in discrete_element; b : in discrete_element) return discrete_element is tmp : Double := Double (a) * Double (b) / Double (gcd (a, b)); result : discrete_element; begin tmp := Double'Floor (tmp); result := discrete_element (tmp); return result; end lcm; function lcm (a : in discrete_element; b : in discrete_element) return Double is tmp : constant Double := Double (a) * Double (b) / Double (gcd (a, b)); begin return Double'Floor (tmp); end lcm; end discrete_util;