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.2 required=5.0 tests=BAYES_00,FROM_LOCAL_HEX, FROM_STARTS_WITH_NUMS autolearn=no 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-7-bit Received: by 10.66.88.231 with SMTP id bj7mr6001540pab.45.1350545738588; Thu, 18 Oct 2012 00:35:38 -0700 (PDT) MIME-Version: 1.0 Path: s9ni20901pbb.0!nntp.google.com!news.glorb.com!feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: =?UTF-8?Q?Vinzent_H=C3=B6fler?= <0439279208b62c95f1880bf0f8776eeb@t-domaingrabbing.de> Newsgroups: comp.lang.ada Subject: Re: Fixed Point number mul, is it a bug? Date: Thu, 18 Oct 2012 09:35:21 +0200 Message-ID: References: <422cd822-6d9a-4909-9009-995d845180b8@googlegroups.com> <422cd822-6d9a-4909-9009-995d845180b8@googlegroups.com> X-Trace: individual.net tonFb8wzubIeAXdP6ZtbBAGTkY87mJpRW2Emc7wYohmxzJfC9lz1ajbnxKE0GgfSv5 Cancel-Lock: sha1:qonMJa5lr8Y/zOavBBgEoHR7rEs= In-Reply-To: <422cd822-6d9a-4909-9009-995d845180b8@googlegroups.com> User-Agent: Groundhog Newsreader for Android Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: 2012-10-18T09:35:21+02:00 List-Id: 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. > Why not: 0.02 0.04 0.08 0.16 0.32 ? Because 0.01 is not representable in a finite, binary number. > If FP declared as > "type FP is delta 0.01 digits 4", > it yield expected results. Yes. In that case you're requesting a decimal type which is required to be exact. So, no, this is not a bug. Vinzent.