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,UTF8 Received: by 10.180.84.74 with SMTP id w10mr1445263wiy.4.1350556946478; Thu, 18 Oct 2012 03:42:26 -0700 (PDT) Path: q11ni134359567wiw.1!nntp.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.139.MISMATCH!xlned.com!feeder7.xlned.com!news2.euro.net!feeds.phibee-telecom.net!dedekind.zen.co.uk!zen.net.uk!hamilton.zen.co.uk!163.1.2.201.MISMATCH!feeds.news.ox.ac.uk!news.ox.ac.uk!not-for-mail From: Ian Clifton Newsgroups: comp.lang.ada Subject: Re: Fixed Point number mul, is it a bug? Date: Thu, 18 Oct 2012 11:42:26 +0100 Organization: Oxford University Message-ID: References: <422cd822-6d9a-4909-9009-995d845180b8@googlegroups.com> NNTP-Posting-Host: chem-arachne.chem.ox.ac.uk Mime-Version: 1.0 X-Trace: news.ox.ac.uk 1350556946 10592 129.67.70.197 (18 Oct 2012 10:42:26 GMT) X-Complaints-To: newsmaster@ox.ac.uk NNTP-Posting-Date: Thu, 18 Oct 2012 10:42:26 +0000 (UTC) X-Face: UBC;x(*[G|MjJprNEe46g'_ohKo&_1j)xyO.Vp{Aqs]utmX:;onqsta@HWuZ/XLcnUl8:Tw ftqJ]_NiENI}83q%~[/2C!f[!&@p*N9'-weU1%|76wuw7,u$vB:Q2/rT:Xt7/vlATc]_'O$o +$BJ~I+H|df*r>lC?,P?s4W"HC]fP0FT+Ay5.0R{rc0)JICp(z:[gx9k'/JC|hnzbW@#"[t;'I0` User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-GB Date: 2012-10-18T11:42:26+01:00 List-Id: "Dmitry A. Kazakov" writes: > On Thu, 18 Oct 2012 00:11:32 -0700 (PDT), 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 >> >> Why not: 0.02 0.04 0.08 0.16 0.32 ? > > If you try this one: > > Ada.Text_IO.Put_Line("List:"); > loop > Ada.Text_IO.Put_Line("x =>" & FP'Image(x)); > exit when x = FP'Last; > x := FP'Succ (x); > end loop; > > you will see what is going on. A binary fixed point type has values which > are not necessarily exact decimal ones. In RM's language it would read as > "the small" is not a power of 10. The small is the difference between two > adjacent values. > >> If FP declared as "type FP is delta 0.01 digits 4", >> it yield expected results. > > Because this makes it decimal = the small is a power of 10 = values are > exactly decimal. See 3.5.9(9) Didn’t some IBM machines have a floating‐point format where the exponent was decimal rather than binary? -- Ian ◎