comp.lang.ada
 help / color / mirror / Atom feed
From: sphinx.moro@wanadoo.fr (SPHINX)
Subject: Semantic of the mod operator in Ada 83
Date: 6 Mar 2004 01:45:03 -0800
Date: 2004-03-06T01:45:03-08:00	[thread overview]
Message-ID: <464ad5ee.0403060145.6c03b8d9@posting.google.com> (raw)

I just wander what is the semantic of
What is the exact semantic
of the function mod  in that case?
-- Compiler is gnat 3.15
-- modular types are not used, because the mode shall be Ada83

with text_io;
use  text_io;
procedure counter is
  	Size : constant := 32;
  	type Counter is range 0 .. (2 ** 31) - 1;  -- = 0..2147483647
  	for  Counter'Size use Size;

	V1  : Counter := Counter'LAST;
	V2  : Counter := Counter'LAST;
	R   : Counter := 0;
	Z   : Counter := 0;
	function Add (Val1 :in Counter;Val2 :in Counter) return Counter is
	begin
	  return ((Val1+Val2) mod Counter'Last);
	end Add;
	package counter_io is new integer_io(Counter);use counter_io;
begin
	put("V1=");	counter_io.put(V1);new_line;
	put("V2=");	counter_io.put(V2);new_line;
	R := Add (V1, V2);
	put("R=");counter_io.put(R);new_line;
	--Result for GNAT 3.15 => R=-2
	put("LAST=");put(Counter'Last);new_line;
	R := V1+V2;
	put("R=");counter_io.put(R);new_line;
	Z := R;
	put("Z=");counter_io.put(Z);new_line;
end counter;

And why there is no containt error on the direct additions
Thanks for the help



             reply	other threads:[~2004-03-06  9:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-06  9:45 SPHINX [this message]
2004-03-06 12:05 ` Semantic of the mod operator in Ada 83 Jeff C,
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox