comp.lang.ada
 help / color / mirror / Atom feed
From: "Stuart" <stuart@0.0>
Subject: Re: conversions between fixed-point types
Date: Mon, 28 Sep 2009 14:40:32 +0100
Date: 2009-09-28T14:40:32+01:00	[thread overview]
Message-ID: <4ac0bcbd$1_1@glkas0286.greenlnk.net> (raw)
In-Reply-To: 35adcbc7-dec6-45ae-bf80-1ebb7a058507@l35g2000vba.googlegroups.com


"sjw" <simon.j.wright@mac.com> wrote in message 
news:35adcbc7-dec6-45ae-bf80-1ebb7a058507@l35g2000vba.googlegroups.com...
> On Sep 25, 9:47 am, "Stuart" <stu...@0.0> wrote:
> "Adam Beneschan" <a...@irvine.com> wrote in message
..
> > Dirk Herrmann wrote:
DH> FpB'Image(FpB'(-1.5)) evaluates to -1.2
DH> FpB'Image(FpB(FpA'(-1.5))) evaluates to -1.2
DH> FpB'Image(MakeBFromA(FpA'(-1.5))) evaluates to -1.6

AB> The answer is curious (and I'm not sure if it's what the language
AB> designers intended). 4.9(38) says, ...
AB> ...
AB> If FpB'Machine_Rounds is FALSE, though, the situation is interesting.
AB> 4.9(38) requires that static expressions get *truncated* toward zero,
AB> as I read it. But there's no similar requirement for expressions
AB> computed at runtime.

S> Having played with this on GNATPro 6.1.2 (to PC target) it does report
S> FpB'Machine_Rounds as false. It also rounds values like -1.59999 down to
S> -1.2 (which is a logical consequence). Technically this is still within 
the
S> error bounds declared for FpB (delta 0.4) so it is not "wrong" within the
S> rules of the language definition. But it is very counter-intuitive and is
S> the sort of thing I find frustrating.
S>
S> I also tested the problem on GreenHills AdaMULTI (4.2.3 to PowerPC 
target);
S> this gave FpB'Machine_Rounds as true and gave the more intuitive results.
S>
S> -1.5 -> -1.6
S> -1.40001 -> -1.6
S> -1.4 -> -1.2
S>
S> So although there does look to be a language "gotcha" here, it depends 
upon
S> the compiler's choice of 'Machine_Rounds.

SW> This is all very weird. Can I point you to my earlier post at
SW> http://groups.google.com/group/comp.lang.ada/msg/f79a71b9abe7e287
SW> which (unless I'm deluded) shows GNAT rounding away from zero for
SW> dynamic values even though 'Machine_Rounds is False!! (and I get the
SW> same results on Ubuntu 8.04 with GNAT GPL 2008.

Sorry for any confusion Simon, I was stating my results for static values; 
for computed/dynamic conversions GNAT does round to nearest (so, away from 0 
for -1.5).
-- 
Stuart 





  parent reply	other threads:[~2009-09-28 13:40 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-18 21:35 conversions between fixed-point types Dirk Herrmann
2009-09-18 22:42 ` Adam Beneschan
2009-09-19 12:41 ` Dirk Herrmann
2009-09-19 14:48   ` John B. Matthews
2009-09-20  8:15     ` Dirk Herrmann
2009-09-20 14:22       ` Robert A Duff
2009-09-20 18:55         ` Dirk Herrmann
2009-09-20 20:34           ` Simon Clubley
2009-09-23 20:46             ` Dirk Herrmann
2009-09-27 17:15               ` Simon Clubley
2009-09-27 19:22           ` sjw
2009-09-28 20:18             ` Dirk Herrmann
2009-09-28 18:37           ` Robert A Duff
2009-09-28 20:50             ` Dirk Herrmann
2009-09-20 15:18       ` John B. Matthews
2009-09-20 19:13         ` Dirk Herrmann
2009-09-20 20:09       ` tmoran
2009-09-21 17:24       ` Jeffrey R. Carter
2009-09-23 20:57         ` Dirk Herrmann
2009-09-23 22:28           ` Jeffrey R. Carter
2009-09-24  1:05             ` Adam Beneschan
2009-09-24  3:57               ` Jeffrey R. Carter
2009-09-25  8:47               ` Stuart
2009-09-25 20:41                 ` sjw
2009-09-25 21:58                   ` Jeffrey R. Carter
2009-09-28 13:40                   ` Stuart [this message]
2009-09-26 14:43                 ` Dirk Herrmann
2009-09-28 15:15                   ` Adam Beneschan
2009-09-26 14:31               ` Dirk Herrmann
2009-09-19 18:38   ` tmoran
2009-09-20  8:22 ` sjw
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox