comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
To: "Lars" <lars-remove_me-m@gmx.net>,
	"comp.lang.ada@ada.eu.org" <comp.lang.ada@ada-france.org>
Subject: Re: Modular integers
Date: Tue, 28 Oct 2003 12:50:05 -0600
Date: 2003-10-28T12:50:05-06:00	[thread overview]
Message-ID: <mailman.238.1067367050.25614.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: bnm6vh$ebj$06$1@news.t-online.com

"Lars" <lars-remove_me-m@gmx.net> wrote in message
news:bnloh2$q3d$03$1@news.t-online.com...
> Yes, it is not "reset".  I don't know a better word to describe it ...

How about "wraps" or "wraps around"?

>
> Why couldn't the compiler insert code that checks what the upper limit of
> the type is, then substracts the current value of the variable from the
> upper limit to see if the difference is bigger or equal to the number you
> want to add? If it is not, it could throw an exception ...
It cannot raise an exception because the langeage definition (RM95 3.5.4)
defines
a modular type as one in which all arithmetic is _modulo_ the specified
modulus --
i.e. with "wrap-around" semantics.

>
>
> > No.  By definition modular numbers cannot "overflow."  In fact, to say
the
> > value
> > is "reset" to 0 is incorrect.  0 simply follows 2**64 - 1.
> >
> > You can declare a _signed_ 64-bit integer type which will overflow when
> > adding
> > 1 to 2**63-1, or underflow when subtracting 1 from -(2**63).
>
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
>




  reply	other threads:[~2003-10-28 18:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-28 12:13 Modular integers Lars
2003-10-28 12:28 ` David C. Hoos
2003-10-28 12:48   ` Lars
2003-10-28 14:13     ` Vinzent 'Gadget' Hoefler
2003-10-28 16:55       ` Lars
2003-10-28 18:50         ` David C. Hoos [this message]
2003-10-28 20:46           ` Lars
2003-10-29  8:30         ` Vinzent 'Gadget' Hoefler
2003-10-29 10:39           ` Jean-Pierre Rosen
2003-10-29 12:16             ` Vinzent 'Gadget' Hoefler
2003-10-29  1:51 ` Raising exceptions (was: Modular integers) Jeffrey Carter
2003-10-29  3:02   ` Raising exceptions Hyman Rosen
replies disabled

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