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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!p9g2000vbl.googlegroups.com!not-for-mail From: sjw Newsgroups: comp.lang.ada Subject: Re: conversions between fixed-point types Date: Sun, 20 Sep 2009 01:22:07 -0700 (PDT) Organization: http://groups.google.com Message-ID: <183ee354-79d7-4373-8acb-c7d43f017d52@p9g2000vbl.googlegroups.com> References: NNTP-Posting-Host: 82.30.110.254 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1253434927 24842 127.0.0.1 (20 Sep 2009 08:22:07 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 20 Sep 2009 08:22:07 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p9g2000vbl.googlegroups.com; posting-host=82.30.110.254; posting-account=_RXWmAoAAADQS3ojtLFDmTNJCT0N2R4U User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8402 Date: 2009-09-20T01:22:07-07:00 List-Id: On Sep 18, 10:35=A0pm, Dirk Herrmann wrote: > I realized that with GNAT for the following example types > =A0 =A0 type FpA is delta 0.5 range -10.0 .. +10.0; > =A0 =A0 for FpA'Small use 0.5; > =A0 =A0 type FpB is delta 0.4 range -10.0 .. +10.0; > =A0 =A0 for FpB'Small use 0.4; > conversions from FpA to FpB work as follows: > > =A0 =A0 FpA =A0 =A0 =A0 FpB > =A0 =A0 -1.5 ---> -1.2 > =A0 =A0 -1.0 ---> -0.8 > =A0 =A0 -0.5 ---> -0.4 > =A0 =A0 -0.0 ---> -0.0 > =A0 =A0 +0.5 ---> +0.4 > =A0 =A0 +1.0 ---> +0.8 > =A0 =A0 +1.5 ---> +1.2 > > That is, the conversion is performed similar to a truncation (always > choosing the closest value towards zero). I don't see this; GNAT rounds .. with Ada.Text_IO; use Ada.Text_IO; procedure Fixed is type FpA is delta 0.5 range -10.0 .. +10.0; for FpA'Small use 0.5; type FpB is delta 0.4 range -10.0 .. +10.0; for FpB'Small use 0.4; F : FpA'Base; G : FpB'Base; begin F :=3D -3.0; loop exit when F > 3.0; Put_Line (FpA'Image (F) & " " & FpB'Image (FpB (F)) & " " & FpA'Image (FpA (FpB (F)))); F :=3D FpA'Succ (F); end loop; New_Line; G :=3D -2.8; loop exit when G > 2.8; Put_Line (FpB'Image (G) & " " & FpA'Image (FpA (G)) & " " & FpB'Image (FpB (FpA (G)))); G :=3D FpB'Succ (G); end loop; end Fixed; The output (Mac OS X, gcc-4.3.3 and GNAT-GPL-2009) is below, I've noted the differences with ?'s: -3.0 -3.2 -3.0 rounded away from 0 -2.5 -2.4 -2.5 -2.0 -2.0 -2.0 -1.5 -1.6 -1.5 " ? -1.0 -1.2 -1.0 " ? -0.5 -0.4 -0.5 0.0 0.0 0.0 0.5 0.4 0.5 1.0 1.2 1.0 " ? 1.5 1.6 1.5 " ? 2.0 2.0 2.0 2.5 2.4 2.5 3.0 3.2 3.0 " -2.8 -3.0 -3.2 " and final value /=3D initial value -2.4 -2.5 -2.4 " -2.0 -2.0 -2.0 -1.6 -1.5 -1.6 -1.2 -1.0 -1.2 -0.8 -1.0 -1.2 " " -0.4 -0.5 -0.4 " 0.0 0.0 0.0 0.4 0.5 0.4 0.8 1.0 1.2 " " 1.2 1.0 1.2 1.6 1.5 1.6 2.0 2.0 2.0 2.4 2.5 2.4 " 2.8 3.0 3.2 " "