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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fcf8ea94b94d6941 X-Google-Attributes: gid103376,public From: Marin David Condic Subject: Re: Modular type. What is it and why? Date: 1999/04/05 Message-ID: <3708F1E4.4082DC78@pwfl.com>#1/1 X-Deja-AN: 462931421 Content-Transfer-Encoding: 7bit Sender: condicma@bogon.pwfl.com References: <7ean3c$79m$1@eol.dd.chalmers.se> Content-Type: text/plain; charset=us-ascii Organization: Pratt & Whitney Mime-Version: 1.0 Reply-To: diespammer@pwfl.com Newsgroups: comp.lang.ada Date: 1999-04-05T00:00:00+00:00 List-Id: Staffan Dittmer wrote: > > This might be a simple one but i can't figure it out. > What is a modular type, as opposed to the integer? > When is it useful? > Since ada relies so heavily on types I guess it's not by accident that the standard library includes modular_io. > But why? > Could someone please enlighten me on this subject. > An example of usage would be nice. > I've checked the RM but to be perfectly honest I didn't understand it. > Integer types are pretty much what you would expect: a means of representing integer values both positive and negative. A typical integer may, for example, be used to represent numbers between -32768..32767. Ada gives you predefined integer types known as Integer, Long_Integer, Short_Integer and (at the discretion of the implementation) there may be others as well. Modular types are also a means of representing integer values, but only non-negative values. For example, a declaration such as: type My_Modular_Type is mod 2**16 ; would be able to take on values between 0..65535. Ada does not define any standard Modular types - unless you want to count what you may find in the packages Interfaces and Interfaces.C (See appendix B.2 and B.3 of the ARM) to be "standard". The real interesting usage of Modular types has to do with the operations on them. Arithmetic has "wrap around" semantics - that is: X : My_Modular_Type := 65535 ; ... X := X + 1 ; -- X now = 0. Also you get logical "and" "or" and "not" between two modular objects. If you count what is in the package Interfaces (see appendix B.2 of the ARM) you also get shift and rotate operations on modular types. (Its just that the types and sizes are going to be implementation defined, rather than guaranteed sizes by virtue of the language standard.) Modular types were invented to fill a void in Ada83 - the need that many embedded systems have for dealing with unsigned integers on which you could perform bitwise operations. They also prove useful for other things where the wraparound math is handy. Hope this helps. -- Marin David Condic Real Time & Embedded Systems, Propulsion Systems Analysis United Technologies, Pratt & Whitney, Large Military Engines M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600 ***To reply, remove "bogon" from the domain name.***