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,6fb545e0f992d3a9,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-09 09:00:18 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!howland.erols.net!news-out.nntp.airnews.net.MISMATCH!cabal10.airnews.net!news.airnews.net!cabal11.airnews.net!news.airnews.net!news.cadence.com!not-for-mail From: Paul Graham Newsgroups: comp.lang.ada Subject: Wraparound on multiply overflow Date: Wed, 08 Aug 2001 14:16:03 -0700 Organization: Cadence Design System, Inc. Message-ID: <3B71AC13.F67BDC2@cadence.com> NNTP-Posting-Host: morph.cadence.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.51 [en] (X11; I; SunOS 5.5.1 sun4u) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:11688 Date: 2001-08-08T14:16:03-07:00 List-Id: In C it is defined that the result of multiplying two unsigned integers is the mathematical result modulo the value (int_max + 1), where int_max is the maximum unsigned integer. I'm interested in porting to Ada a random number generator which relies on this rule. The code looks like: unsigned int X[10]; ... X[0] = seed; for (i = 1; i <= 10; i++) X[i] = X[i-1] * 12345; The idea is that a table of random looking numbers is created by repeated multiplication of a seed by some constant. This sequence is guaranteed to be the same across conforming C implementations, because of the modulo rule I mentioned above. Can this code be written in Ada? A few iterations of the loop would result in a range error or overflow. I could suppress checks, but would the result of an overflowing multiply be defined in that case? Is there any other way of emulating C's behavior for this program? I know that Ada has modular types, but these don't work with multiply, do they? Paul