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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.141.76 with SMTP id rm12mr1711452pab.37.1435324827161; Fri, 26 Jun 2015 06:20:27 -0700 (PDT) X-Received: by 10.182.68.51 with SMTP id s19mr7387obt.6.1435324827121; Fri, 26 Jun 2015 06:20:27 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!feeder.erje.net!us.feeder.erje.net!news.ripco.com!news.glorb.com!m20no53108iga.0!news-out.google.com!kd3ni18093igb.0!nntp.google.com!m20no31843iga.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 26 Jun 2015 06:20:26 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=74.203.194.21; posting-account=bXcJoAoAAAAWI5APBG37o4XwnD4kTuQQ NNTP-Posting-Host: 74.203.194.21 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <249bcd57-3074-4566-b8f2-03e6923bfbce@googlegroups.com> Subject: Fixed-point question From: Patrick Noffke Injection-Date: Fri, 26 Jun 2015 13:20:27 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:26484 Date: 2015-06-26T06:20:26-07:00 List-Id: Why are C1 and C2 different? with Ada.Text_IO; procedure FP_Test is type Fixed_Type is delta 1.0 / 180.0 range 0.0 .. 65535.0 / 180.0; N : constant := 0.2; D : constant := 4.5 / 330.0; -- 0.013636 C1 : constant Fixed_Type := Fixed_Type (N / D); C2 : constant Fixed_Type := N / D; begin Ada.Text_IO.Put_Line ("C1 := " & C1'Img); Ada.Text_IO.Put_Line ("C2 := " & C2'Img); end FP_Test; $ ./fp_test C1 := 14.664 C2 := 17.000 I am using GNAT on Fedora 21 (x86_64) and GNAT 2014 for ARM-ELF (Linux-hosted). The output above is on Fedora. In the ARM processor (Cortex-M4), C1 is 14.667 and C2 is 18. It appears that for ARM, the compiler is computing C2 as Fixed_Type (N) / Fixed_Type (D), or 0.2 / (2 / 180) = 0.2 / 0.01111 = 18. I'm not sure why C2 is 17 on the Fedora PC. Thanks, Patrick