comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Unsigned Integer Restraint Errors
Date: Mon, 12 Mar 2007 22:04:15 +0100
Date: 2007-03-12T22:04:12+01:00	[thread overview]
Message-ID: <1t64hfr3a6yc9.1a9r7r1p9i4cq$.dlg@40tude.net> (raw)
In-Reply-To: 1173726806.656979.305660@8g2000cwh.googlegroups.com

On 12 Mar 2007 12:13:26 -0700, frikk wrote:

> Thank you for the input. This leaves me with 2 questions:
> 1.  If my input is 2**35, wouldn't this still render the Integer type
> inaccurate? The goal is to be able to use 64 bit integers... I'm
> referring to your example of UNSIGNED_LONG_INT := UNSIGNED_LONG_INT
> (Integer'(X));

I don't understand what are you trying to achieve. Where the input comes
from, and what type it has. I see only two possibilities:

1. The input type is UNSIGNED_LONG_INT, where is the problem? It is in the
range. -5 in your example is not a number, it is an expression of
UNSIGNED_LONG_INT and its result is in the range of. If the semantics of
"-" bothers you, redefine it:

   function "-" (Left : UNSIGNED_LONG_INT) return UNSIGNED_LONG_INT is
   begin
      if Left = 0 then
         return Left;
      else
         raise Constraint_Error; -- No wrapping
      end if;
   end "-";

or else disallow it altogether:

   function "-" (Left : UNSIGNED_LONG_INT) return UNSIGNED_LONG_INT
       is abstract;

2. The type is some different type. You have to convert it to
UNSIGNED_LONG_INT and if its value is outside UNSIGNED_LONG_INT'Range you
will get Constraint_Error. Again, no problem in sight.

It is safe in all cases.

-------
When you use Integer, it is to expect that on most machines
Integer'Last<System.Max_Binary_Modulus. But, again, I probably don't
understand your problem, because I don't see in the first place why you
wanted to convert signed integers to modular integers. As Randy has already
suggested, declare it signed natural and enjoy range checks.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



      parent reply	other threads:[~2007-03-12 21:04 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-12 15:07 Unsigned Integer Restraint Errors frikk
2007-03-12 16:27 ` Georg Bauhaus
2007-03-12 17:17 ` Adam Beneschan
2007-03-12 17:23 ` Adam Beneschan
2007-03-12 18:11   ` frikk
2007-03-12 20:00     ` frikk
2007-03-12 20:07       ` Adam Beneschan
2007-03-12 18:00 ` Dmitry A. Kazakov
2007-03-12 19:00   ` Martin Krischik
2007-03-12 21:13     ` Dmitry A. Kazakov
2007-03-12 19:13   ` frikk
2007-03-12 19:22     ` Randy Brukardt
2007-03-13  3:13       ` Jeffrey R. Carter
2007-03-13  3:00         ` Randy Brukardt
2007-03-13 12:09           ` frikk
2007-03-13 14:58             ` frikk
2007-03-13 15:31               ` frikk
2007-03-13 15:59                 ` Robert A Duff
2007-03-13 16:18                 ` Dmitry A. Kazakov
2007-03-13 16:21                 ` Jeffrey R. Carter
2007-03-13 16:04               ` Adam Beneschan
2007-03-13 16:41                 ` Adam Beneschan
2007-03-13 16:42                   ` Adam Beneschan
2007-03-14 14:06                     ` frikk
2007-03-13 17:23                 ` Dmitry A. Kazakov
2007-03-13 17:31                   ` Adam Beneschan
2007-03-14  0:54                   ` Jeffrey R. Carter
2007-03-16 13:38                   ` frikk
2007-03-13 16:16           ` Jeffrey R. Carter
2007-03-12 21:04     ` Dmitry A. Kazakov [this message]
replies disabled

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