comp.lang.ada
 help / color / mirror / Atom feed
From: Jim Rogers <jimmaureenrogers@worldnet.att.net>
Subject: Re: Signed integer to modular type conversion
Date: Wed, 15 May 2002 03:34:15 GMT
Date: 2002-05-15T03:34:15+00:00	[thread overview]
Message-ID: <3CE1D73A.8010401@worldnet.att.net> (raw)
In-Reply-To: b4682ab7.0205141853.7e835874@posting.google.com

Adam Beneschan wrote:

> Supposing Standard.Integer is a 32-bit signed integer type.  I have a
> modular type
> 
>     type ModType is mod 2**32;
> 
>     X : Integer;
>     Y : ModType;
> 
> I'd like to set Y := X mod 2**32 (which should essentially just treat
> X as an unsigned integer without changing the data).  However, I can't
> figure out a good way to do this in Ada.  


Try the following example.

with Ada.Text_Io;
procedure Convert is
    type ModType is mod 2**32;
    X: Integer;
    Y: ModType := ModType'First;
begin
    loop
       X := Integer(Y);
       Ada.Text_IO.Put_Line("Value:" & Integer'Image(X));
       exit when Y = ModType'Last;
       Y := Y + 1;
    end loop;
end Convert;

You can see that the only real issue is converting the modular type
to an Integer, which is done with simple type coercion.

Jim Rogers




  reply	other threads:[~2002-05-15  3:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-15  2:53 Signed integer to modular type conversion Adam Beneschan
2002-05-15  3:34 ` Jim Rogers [this message]
2002-05-15 14:01 ` Mark Johnson
2002-05-16  0:02   ` Adam Beneschan
2002-05-16  2:26     ` Steven Deller
2002-05-16  9:53     ` Robert Dewar
2002-05-16 13:46       ` Steve Doiel
2002-05-16 14:00       ` Mark Johnson
2002-05-16 15:52       ` Adam Beneschan
2002-05-17  2:26         ` Robert Dewar
2002-05-17 16:44           ` Frank J. Lhota
2002-05-16 13:55     ` Mark Johnson
2002-05-15 19:12 ` Robert Dewar
2002-05-15 20:28 ` Adam Beneschan
  -- strict thread matches above, loose matches on Subject: below --
2002-05-15  5:43 Grein, Christoph
2002-05-16  4:39 Grein, Christoph
2002-05-16 14:13 ` Mark Johnson
replies disabled

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