------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Cheddar is a GNU GPL real-time scheduling analysis tool. -- This program provides services to automatically check schedulability and -- other performance criteria of real-time architecture models. -- -- Copyright (C) 2002-2020, Frank Singhoff, Alain Plantec, Jerome Legrand, -- Hai Nam Tran, Stephane Rubini -- -- The Cheddar project was started in 2002 by -- Frank Singhoff, Lab-STICC UMR CNRS 6285, Universite de Bretagne Occidentale -- -- Cheddar has been published in the "Agence de Protection des Programmes/France" in 2008. -- Since 2008, Ellidiss technologies also contributes to the development of -- Cheddar and provides industrial support. -- -- The full list of contributors and sponsors can be found in AUTHORS.txt and SPONSORS.txt -- -- 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$ -- $Date$ -- $Author: singhoff $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with text_io; use text_io; with Ada.Numerics.Aux; use Ada.Numerics.Aux; procedure tlcm is package double_io is new Text_IO.Float_IO (Double); use double_io; function double_rem (a : Double; b : Double) return Double is result : Double; begin result := a - Double'Floor (a / b) * b; return (result); end double_rem; function double_mod (a : Double; b : Double) return Double is result : Double; begin result := double'floor(a/b); result := a - b * result; return (result); end double_mod; function gcd (left : double; right : double) return double is min : double:= double'Min (left, right); max : double:= double'Max (left, right); remainder : double; begin reduce : loop if min <= 0.0 then return max; end if; remainder := double_rem(max, min); max := min; min := remainder; end loop reduce; end gcd; function lcm (a : in double; b : in double) return Double is tmp : constant Double := a * b / (gcd (a, b)); begin return Double'Floor (tmp); end lcm; res : double; begin res:=double_mod(5.0, 2.0); put("5 mod 2 = "); put(res,3,0); new_line; res:=double_mod(11.0, 3.0); put("11 mod 3 = "); put(res,3,0); new_line; res:=double_rem(5.0, 2.0); put("5 rem 2 = "); put(res,3,0); new_line; res:=double_rem(6.0, 3.0); put("6 rem 3 = "); put(res,3,0); new_line; res:=double_rem(11.0, 3.0); put("11 rem 3 = "); put(res,3,0); new_line; res:=lcm(1.0, 2.0); put("lcm(1,2) = "); put(res,3,0); new_line; res:=lcm(6.0, 7.0); put("lcm(6,7) = "); put(res,3,0); new_line; end tlcm;