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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,dbbfdf636aaea0f8,start X-Google-Attributes: gid103376,public From: David Shochat Subject: modular arithmetic bug in gnat? Date: 2000/02/09 Message-ID: <38A144A0.141EA33F@chelmsford.com>#1/1 X-Deja-AN: 583604769 Content-Transfer-Encoding: 7bit X-Accept-Language: en, mk, sv, fr Content-Type: text/plain; charset=us-ascii X-Abuse-Info: Otherwise we will be unable to process your complaint properly X-Complaints-To: admin@usenetserver.com Organization: UseNet Server, Inc. http://www.usenetserver.com - Home of the fastest NNTP servers on the Net. MIME-Version: 1.0 NNTP-Posting-Date: Wed, 09 Feb 2000 05:40:03 EST Newsgroups: comp.lang.ada Date: 2000-02-09T00:00:00+00:00 List-Id: The following test is the result of distilling an issue that came up at work: with Ada.Text_Io; procedure Mod_Test is type M_2_16 is mod 2 ** 16; K : M_2_16 := 11_111; A : constant Integer := Integer(K * 1000 / 25); begin Ada.Text_Io.Put ("A = " & Integer'Image(A)); end Mod_Test; When I run this with gnat (3.12p, Linux) the answer is 51224. This is evidently the result of delaying the reduction mod 2**16 until after the division. The same program on Rational Apex (3.2.0b, HP-UX 11.0) gives 1416 which is what you get if you reduce mod 2**16 immediately after the multiplication but before the division. Now based on 4.5(13), the result should be as if the operations were performed left to right, i.e. multiplication followed by division. But each of those operations must be as defined for the modular type, and 4.5.5(10) implies that the first operation is defined as including a reduction. So the correct result must be ((11111 * 1000) mod 2**16) / 25, i.e. 1416. Do you agree? -- David