From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
Subject: Re: Modular integers
Date: Tue, 28 Oct 2003 06:28:29 -0600
Date: 2003-10-28T06:28:29-06:00 [thread overview]
Message-ID: <Pftnb.86846$5n.57615@bignews5.bellsouth.net> (raw)
In-Reply-To: bnlmg1$kqv$04$1@news.t-online.com
"Lars" <lars-remove_me-m@gmx.net> wrote in message
news:bnlmg1$kqv$04$1@news.t-online.com...
> Hi,
>
> I was able to create an unsigned 64-bit integer using
>
> type unsigned_64_bit_integer is mod 2**64;
>
> Then I defined a subtype:
>
> subtype safe_unsigned_64_bit_integer is unsigned_64_bit_integer range
0
> .. 2**64-1;
>
> When a variable of type unsigned_64_bit_integer contains 2**64-1 and you
add
> 1, it is "reset" to 0, as expected.
> When a variable of type safe_unsigned_64_bit_integer contains 2**64-1 and
> you add 1, no exception is raised and it is "reset" to 0.
>
> Why is that? Shouldn't the compiler be able to insert a check that throws
an
> exception if an overflow occurs?
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).
>
> -Lars
>
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
>
>
next prev parent reply other threads:[~2003-10-28 12:28 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 [this message]
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
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