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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,32c6d2fb891775fc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-29 00:32:04 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!adsl-213-200-246-247.cybernet.CH!not-for-mail From: Vinzent 'Gadget' Hoefler Newsgroups: comp.lang.ada Subject: Re: Modular integers Date: Wed, 29 Oct 2003 09:30:41 +0100 Organization: JeLlyFish software Message-ID: References: Reply-To: v.hoefler@acm.org NNTP-Posting-Host: adsl-213-200-246-247.cybernet.ch (213.200.246.247) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de 1067416322 37728894 213.200.246.247 (16 [175126]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:1799 Date: 2003-10-29T09:30:41+01:00 List-Id: Lars wrote: >>> Isn't that the expected result? > >Thank you Vinzent! Oddly enough it seems totally self-explanatory now = ... >I have totally forgotten which misconception had bothered me. Well, I thought about what I wrote and became unsure about it. ;) So to prove my point I enhanced the little test program: |with Ada.Text_IO; | |procedure t is | type X_Base is mod 2**64; | subtype X_1 is X_Base range 0 .. 2**64 - 1; | subtype X_2 is X_Base range 0 .. 2**64 - 2; | | A : X_Base; | B : X_1; | C : X_2; | |begin | begin | Ada.Text_IO.Put ("A'Last + 1: "); | A :=3D X_Base'Last; | Ada.Text_IO.Put (X_Base'Image (A)); | A :=3D A + 1; | Ada.Text_IO.Put (X_Base'Image (A)); | exception | when Constraint_Error =3D> | Ada.Text_IO.Put (" Constraint_Error"); | end; | | Ada.Text_IO.New_Line; | | begin | Ada.Text_IO.Put ("B'Last + 1: "); | B :=3D X_1'Last; | Ada.Text_IO.Put (X_Base'Image (B)); | B :=3D B + 1; | Ada.Text_IO.Put (X_Base'Image (B)); | exception | when Constraint_Error =3D> | Ada.Text_IO.Put (" Constraint_Error"); | end; | | Ada.Text_IO.New_Line; | | begin | Ada.Text_IO.Put ("C'Last + 1: "); | C :=3D X_2'Last; | Ada.Text_IO.Put (X_Base'Image (C)); | C :=3D C + 1; | Ada.Text_IO.Put (X_Base'Image (C)); | exception | when Constraint_Error =3D> | Ada.Text_IO.Put (" Constraint_Error"); | end; | | Ada.Text_IO.New_Line; | | begin | Ada.Text_IO.Put ("C'Last + 2: "); | C :=3D X_2'Last; | Ada.Text_IO.Put (X_Base'Image (C)); | C :=3D C + 2; | Ada.Text_IO.Put (X_Base'Image (C)); | exception | when Constraint_Error =3D> | Ada.Text_IO.Put (" Constraint_Error"); | end; |end t; The output is as I hoped, if not to say "as I expected", but IMO quite interesting: |A'Last + 1: 18446744073709551615 0 |B'Last + 1: 18446744073709551615 0 |C'Last + 1: 18446744073709551614 Constraint_Error |C'Last + 2: 18446744073709551614 0 As you can see, the behaviour of the subtype is absolutely correct, although it might not be intuitive. I mean, adding 1 raises a constraint error while adding 2 (or even more, try it) doesn't. So what we get here is a modular type with range constraints. *That's* interesting... :-) Vinzent.