comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Modular type. What is it and why?
Date: 1999/04/05
Date: 1999-04-05T00:00:00+00:00	[thread overview]
Message-ID: <7eb2iq$jc3@hobbes.crc.com> (raw)
In-Reply-To: 7ean3c$79m$1@eol.dd.chalmers.se


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.







  parent reply	other threads:[~1999-04-05  0:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-05  0:00 Modular type. What is it and why? Staffan Dittmer
1999-04-05  0:00 ` Marin David Condic
1999-04-05  0:00 ` David C. Hoos, Sr. [this message]
1999-04-06  0:00   ` Mike Silva
1999-04-06  0:00     ` Ole-Hjalmar Kristensen
1999-04-06  0:00     ` Marin David Condic
1999-04-06  0:00       ` Mike Silva
1999-04-06  0:00         ` bglbv
1999-04-07  0:00         ` Ole-Hjalmar Kristensen
1999-04-07  0:00           ` Mike Silva
1999-04-07  0:00             ` Stephen Leake
1999-04-08  0:00             ` Ole-Hjalmar Kristensen
1999-04-06  0:00     ` Mike Silva
1999-04-07  0:00       ` Robert Dewar
1999-04-07  0:00         ` Bret
1999-04-11  0:00         ` Florian Weimer
replies disabled

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