------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- 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-2023, 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 README.md -- -- 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;