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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b3e361752e757bb8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.66.86.102 with SMTP id o6mr5810986paz.41.1350571787602; Thu, 18 Oct 2012 07:49:47 -0700 (PDT) Received: by 10.68.240.103 with SMTP id vz7mr5470849pbc.10.1350571787585; Thu, 18 Oct 2012 07:49:47 -0700 (PDT) Path: s9ni21683pbb.0!nntp.google.com!kt20no3648712pbb.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 18 Oct 2012 07:49:47 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ NNTP-Posting-Host: 66.126.103.122 References: <422cd822-6d9a-4909-9009-995d845180b8@googlegroups.com> <422cd822-6d9a-4909-9009-995d845180b8@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <96d9c28c-f199-4c24-b04d-fd565b024bd3@googlegroups.com> Subject: Re: Fixed Point number mul, is it a bug? From: Adam Beneschan Injection-Date: Thu, 18 Oct 2012 14:49:47 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-10-18T07:49:47-07:00 List-Id: On Thursday, October 18, 2012 12:35:38 AM UTC-7, Vinzent H=F6fler wrote: > kylix wrote: >=20 >=20 >=20 > > -- GNAT GPL 2012=20 >=20 > > with Ada.Text_IO; >=20 > > procedure FixPoint is > > type FP is delta 0.01 range 0.00 .. 99.99; > > -- type FP is delta 0.01 digits 4; > > x : FP :=3D 0.01; > > begin > > for i in 1 .. 5 loop > > x :=3D x * 2; > > Ada.Text_IO.Put_Line("x =3D>" & > > FP'Image(x));=20 > > end loop; > > end Fixpoint; >=20 >=20 >=20 > > In my machine, it yield results: >=20 > > x =3D> 0.02 > > x =3D> 0.03 > > x =3D> 0.06 > > x =3D> 0.13 > > x =3D> 0.25 >=20 > This is expected. The definition requests a fixed point type with a=20 > delta of at least 0.01, most compilers would choose 2**-7 then, which=20 > 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 pow= er of two if not specified (3.5.9(8)). The 'Small has to be no greater tha= n the specified delta, and most compilers would choose the largest power of= 2 that is <=3D the delta. (This applies only to ordinary fixed-point type= s, not those with "digits" in the declaration.) Shark8 showed how you can = specify the 'Small, although that isn't completely portable because it's al= lowable for compilers not to let you specify a 'Small that isn't a power of= 2 (3.5.9(21)). =20 -- Adam