comp.lang.ada
 help / color / mirror / Atom feed
From: "Lars" <lars-remove_me-m@gmx.net>
Subject: Modular integers
Date: Tue, 28 Oct 2003 13:13:28 +0100
Date: 2003-10-28T13:13:28+01:00	[thread overview]
Message-ID: <bnlmg1$kqv$04$1@news.t-online.com> (raw)

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?

-Lars





             reply	other threads:[~2003-10-28 12:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-28 12:13 Lars [this message]
2003-10-28 12:28 ` Modular integers 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
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