From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,caabf5265fad78e5 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!x3g2000yqa.googlegroups.com!not-for-mail From: Dave Newsgroups: comp.lang.ada Subject: Re: unsigned type Date: Mon, 6 Jul 2009 13:20:45 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <59O1m.404661$4m1.69194@bgtnsc05-news.ops.worldnet.att.net> NNTP-Posting-Host: 130.207.218.196 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1246911647 1402 127.0.0.1 (6 Jul 2009 20:20:47 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 6 Jul 2009 20:20:47 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x3g2000yqa.googlegroups.com; posting-host=130.207.218.196; posting-account=xOI3VwoAAABDSWy00WCXAZywS_1IM1iN User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.11) Gecko/2009060403 Red Hat/3.0.11-4.el4 Firefox/3.0.11,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6864 Date: 2009-07-06T13:20:45-07:00 List-Id: On Jun 29, 9:36=A0am, Rob Solomon wrote: > I was able to use the Natural and Positive. =A0 > > Now I'm trying to understand Mod types. > > I tried this: > type card31 is mod 2_147_483_648; > type card32 is mod 4_294_967_296; > c31 : Card31; > c32: Card32; > LI : Long_Integer; > and > > LI :=3D Long_Integer(c32); > > How to I output c31 and c32? =A0Modula-2 uses WriteCard or CardToString > and WriteString > > I tried using Put, but I got an error saying that correct procedure > could not be found, or something like that. > > Put(LI) works until the value of LI > 2**31, even for c32. > > Thanks for helping > --rob > > On Sun, 28 Jun 2009 19:54:28 +0000 (UTC), tmo...@acm.org wrote: > >>I am trying to declare a type as unsigned using Ubuntu 9.04 GNAT > >>compiler. =A0I know Ada does not have a type CARDINAL, but I thought it > >>had a type Unsigned. > > >Ada's equivalent is Natural. =A0If > > =A0Lowest : Natural :=3D 0; > > =A0Highest : Natural :=3D Natural'last; > >then > > =A0Lowest =A0:=3D Lowest-1; =A0-- will raise an exception > > =A0Highest :=3D Highest+1; -- ditto > > >(Note that Gnat by default is not a legal Ada compiler because it doesn'= t > >check for and raise the exception. =A0You need a command line parameter > >-gnato to make it act like Ada.) > > >The standard Ada package Interfaces has hardware-oriented types > >Unsigned_8, Unsigned_16, etc but those are modular types so if > > =A0Empty_Word : Interfaces.Unsigned_16 :=3D 0; > > =A0Full_Byte =A0: Interfaces.Unsigned_8 :=3D 255; > >then > > =A0Empty_Word-1 will be 65535. > > =A0Full_Byte+1 will be 0. > >with no exceptions raised. > > >You can also declare your own application oriented non-negative types > > =A0type Ratings is range 1 .. 10; > >or modular types > > =A0type Degrees is mod 360; =A0-- 0 .. 359 wrapping around > > I'm an Ada-nub myself, but... You could use c31'Image(A_c31_Type): be aware that Type'Image may put/ often puts a space or spaces in front of the string it generates. More experienced Ada programmers will likely be able to provide a better answer.