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.3 required=5.0 tests=BAYES_00,INVALID_MSGID, LOTS_OF_MONEY 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: "David C. Hoos, Sr." Subject: Re: Modular type. What is it and why? Date: 1999/04/05 Message-ID: <7eb2iq$jc3@hobbes.crc.com>#1/1 X-Deja-AN: 462970090 References: <7ean3c$79m$1@eol.dd.chalmers.se> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Organization: Coleman Research Corporation Newsgroups: comp.lang.ada Date: 1999-04-05T00:00:00+00:00 List-Id: Staffan Dittmer wrote in message <7ean3c$79m$1@eol.dd.chalmers.se>... >This might be a simple one but i can't figure it out. >What is a modular type, as opposed to the integer? A mudular type is one in which incrementing from (modulus -1) gives zero, and when decrementing from zero gives (modulus -1) -- i.e. overflow and underflow cannot occur. E.g. the type mod 2 ** 8, has values 0 .. 255. The type mod 7 has values 0 .. 6. >When is it useful? There are many uses for such a type -- e.g., the index of a circular array, or a representation of the days of the week, such that the successor to the last day of the week is the first day of the week, and the predecesor of the first day of the week is the last day of the week. >Since ada relies so heavily on types I guess it's not by accident that the standard library includes modular_io. >But why? Well.. because someone might want to do IO on mudular types. >Could someone please enlighten me on this subject. >An example of usage would be nice. In general, the unsigned C types in the package Interfaces.C are specified to be modular types, giving them the same behavior as their C counterparts. >I've checked the RM but to be perfectly honest I didn't understand it. RM 95-3.5.4(8) says: The set of values for a signed integer type is the (infinite) set of mathematical integers, though only values of the base range of the type are fully supported for run-time operations. The set of values for a modular integer type are the values from 0 to one less than the modulus, inclusive.