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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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-7-bit Path: g2news2.google.com!news1.google.com!news.glorb.com!news2.glorb.com!news-in-01.newsfeed.easynews.com!easynews!core-easynews-01!easynews.com!en-nntp-09.dc1.easynews.com.POSTED!not-for-mail From: Rob Solomon Newsgroups: comp.lang.ada Subject: Re: unsigned type Message-ID: References: <59O1m.404661$4m1.69194@bgtnsc05-news.ops.worldnet.att.net> X-Newsreader: Forte Agent 4.2/32.1118 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@easynews.com Organization: Forte Inc. http://www.forteinc.com/apn/ X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly. Date: Mon, 29 Jun 2009 09:36:41 -0400 Xref: g2news2.google.com comp.lang.ada:6716 Date: 2009-06-29T09:36:41-04:00 List-Id: I was able to use the Natural and Positive. 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 := Long_Integer(c32); How to I output c31 and c32? Modula-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), tmoran@acm.org wrote: >>I am trying to declare a type as unsigned using Ubuntu 9.04 GNAT >>compiler. I know Ada does not have a type CARDINAL, but I thought it >>had a type Unsigned. > >Ada's equivalent is Natural. If > Lowest : Natural := 0; > Highest : Natural := Natural'last; >then > Lowest := Lowest-1; -- will raise an exception > Highest := Highest+1; -- ditto > >(Note that Gnat by default is not a legal Ada compiler because it doesn't >check for and raise the exception. You 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 > Empty_Word : Interfaces.Unsigned_16 := 0; > Full_Byte : Interfaces.Unsigned_8 := 255; >then > Empty_Word-1 will be 65535. > Full_Byte+1 will be 0. >with no exceptions raised. > >You can also declare your own application oriented non-negative types > type Ratings is range 1 .. 10; >or modular types > type Degrees is mod 360; -- 0 .. 359 wrapping around