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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Fixed-point question Date: Fri, 26 Jun 2015 21:44:04 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <249bcd57-3074-4566-b8f2-03e6923bfbce@googlegroups.com> <6a104bde-67ea-48a5-a035-6be3f9235d42@googlegroups.com> <21e4185b-bc89-4940-b329-09863ad17344@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Sat, 27 Jun 2015 04:42:44 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="a3855fbfe1a666be9aefba0563039ed5"; logging-data="26607"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BlCmSsWqKyob5BEXqz5T0hbyGfTVkBNs=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: <21e4185b-bc89-4940-b329-09863ad17344@googlegroups.com> Cancel-Lock: sha1:lHXcnAkkAWZR9A4H2Z6p3jRXEAA= Xref: news.eternal-september.org comp.lang.ada:26492 Date: 2015-06-26T21:44:04-07:00 List-Id: On 06/26/2015 08:00 PM, Patrick Noffke wrote: > On Friday, June 26, 2015 at 6:13:11 PM UTC-5, qunying wrote: >> In my test with Linux x86_64 with FSF GNAT 4.9.2 >> >> C1 := 14.664 >> C2 := 17.000 >> Small := 3.90625000000000000E-03 >> 1/180 := 5.55555555555555556E-03 >> >> With Jeffrey's changes I got: >> C1 := 14.667 >> C2 := 18.000 >> Small := 5.55555555555555556E-03 >> 1/180 := 5.55555555555555556E-03 >> > > So is this a bug, is the ARM not clear on what should happen here, or is it expected? With a small of 1/180: For C1, AFAICT, the compiler will calculate N/D exactly, getting 44/3 = 14.6666...., and then convert this to Fixed_type, getting 2640/180. For C2, "/" for Fixed_Type is used, so N and D are converted to Fixed_Type first. N = 0.2 = 36/180, and D = 0.013636... is closest to 2/180 = 0.0111... (36/180)/(2/180) = 36/2 = 18. Working out the expected result for the default small of 1/256 is left as an exercise for the reader. -- Jeff Carter "I did not rob a bank. If I'd robbed a bank, everything would be great. I tried to rob a bank, is what happened, and they got me." Take the Money and Run 139