comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Fixed Point number mul, is it a bug?
Date: Thu, 18 Oct 2012 07:49:47 -0700 (PDT)
Date: 2012-10-18T07:49:47-07:00	[thread overview]
Message-ID: <96d9c28c-f199-4c24-b04d-fd565b024bd3@googlegroups.com> (raw)
In-Reply-To: <almarsoft.790144662601357506@news.individual.net>

On Thursday, October 18, 2012 12:35:38 AM UTC-7, Vinzent Höfler wrote:
> kylix wrote:
> 
> 
> 
> > -- GNAT GPL 2012 
> 
> > with Ada.Text_IO;
> 
> > procedure FixPoint is
> >    type FP is delta 0.01 range 0.00 .. 99.99;
> >    -- type FP is delta 0.01 digits 4;
> >    x : FP := 0.01;
> > begin
> >    for i in 1 .. 5 loop
> >       x := x * 2;
> >       Ada.Text_IO.Put_Line("x =>" &
> >                            FP'Image(x)); 
> >    end loop;
> > end Fixpoint;
> 
> 
> 
> > In my machine, it yield results:
> 
> > x => 0.02
> > x => 0.03
> > x => 0.06
> > x => 0.13
> > x => 0.25
> 
> This is expected. The definition requests a fixed point type with a 
> delta of at least 0.01, most compilers would choose 2**-7 then, which 
> is 0.0078125 in decimal notation. Hence the results you see.

To elaborate a bit, the RM says that the 'Small of the type *must* be a power of two if not specified (3.5.9(8)).  The 'Small has to be no greater than the specified delta, and most compilers would choose the largest power of 2 that is <= the delta.  (This applies only to ordinary fixed-point types, not those with "digits" in the declaration.)  Shark8 showed how you can specify the 'Small, although that isn't completely portable because it's allowable for compilers not to let you specify a 'Small that isn't a power of 2 (3.5.9(21)).  

                              -- Adam



  reply	other threads:[~2012-10-18 14:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-18  7:11 Fixed Point number mul, is it a bug? kylix
2012-10-18  7:35 ` Vinzent Höfler
2012-10-18 14:49   ` Adam Beneschan [this message]
2012-10-19  9:09     ` AdaMagica
2012-10-18  7:57 ` Dmitry A. Kazakov
2012-10-18 10:34   ` Georg Bauhaus
2012-10-18 10:42   ` Ian Clifton
2012-10-18 12:37     ` Dmitry A. Kazakov
2012-10-19 22:58       ` Ian Clifton
2012-10-18 14:40     ` Adam Beneschan
2012-10-18 14:04 ` Shark8
replies disabled

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