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 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-15 07:15:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!cpk-news-hub1.bbnplanet.com!cambridge1-snf1.gtei.net!news.gtei.net!bos-service1.ext.raytheon.com!dfw-service2.ext.raytheon.com.POSTED!not-for-mail Message-ID: <3CE26A21.3EC6F802@raytheon.com> From: Mark Johnson X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Signed integer to modular type conversion References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Wed, 15 May 2002 09:01:05 -0500 NNTP-Posting-Host: 192.27.48.39 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.raytheon.com 1021471269 192.27.48.39 (Wed, 15 May 2002 09:01:09 CDT) NNTP-Posting-Date: Wed, 15 May 2002 09:01:09 CDT Organization: Raytheon Company Xref: archiver1.google.com comp.lang.ada:24094 Date: 2002-05-15T09:01:05-05:00 List-Id: Adam Beneschan wrote: > > 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). A reasonably efficient way to do this is Unchecked_Conversion. This for types of the same size (as in this case), it will copy the bytes from the source to destination. As you noted in the rest of your message, the direct type conversion doesn't do what you want and the arithmetic is an inefficient method. There are a lot of reasons not to use Unchecked_Conversion, but this doesn't appear to be one of them. --Mark PS: I don't generally recommend this solution because many use it to excess. Try... with Unchecked_Conversion; function "+" is new Unchecked_Conversion(Integer, Mod_Type); Then your example assignment will be... Y := +X; The abuse comes from using this method for all sorts of type conversions, avoiding type safety, etc.