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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f584bf624aabe591,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-14 19:53:04 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: adam@irvine.com (Adam Beneschan) Newsgroups: comp.lang.ada Subject: Signed integer to modular type conversion Date: 14 May 2002 19:53:04 -0700 Organization: http://groups.google.com/ Message-ID: NNTP-Posting-Host: 66.126.103.122 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1021431184 1153 127.0.0.1 (15 May 2002 02:53:04 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 15 May 2002 02:53:04 GMT Xref: archiver1.google.com comp.lang.ada:24064 Date: 2002-05-15T02:53:04+00:00 List-Id: Supposing Standard.Integer is a 32-bit signed integer type. I have a modular type type ModType is mod 2**32; X : Integer; Y : ModType; I'd like to set Y := X mod 2**32 (which should essentially just treat X as an unsigned integer without changing the data). However, I can't figure out a good way to do this in Ada. Using "mod" won't work, because there is no integer type that can be used as a parameter to "mod" that will take 2**32 as a parameter (I'm assuming that 32 bits is the largest integer type supported by the compiler). A type conversion won't work, because it will raise Constraint_Error if X is negative. I could do something like if X < 0 then Y := ModType (X + ModType'Modulus/2) + ModType'Modulus/2; else Y := ModType (X); end if; but this seems awfully silly for something that really should be just a no-op on the machine. Am I missing something, or is Unchecked_Conversion (or Pragma Suppress) really the only reasonable way to accomplish this? Unless I've forgotten something, it seems quite odd that Ada provides modular types but does not provide a solution for this (other than going through the "back door" by using Unchecked_Conversion or Suppress). If there is no solution, I'd like to propose adding an attribute so that you could write something like Y := ModType'Mod (X); This attribute would be defined for modular types and would return X/ModType'Modulus. I know, "Mod" is a bad name for the attribute. My apologies if this has been discussed at length before. -- Adam