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: a07f3367d7,6a8952cbe009f3ed X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.180.7.228 with SMTP id m4mr1828462wia.3.1360478618204; Sat, 09 Feb 2013 22:43:38 -0800 (PST) Path: bp2ni28189wib.1!nntp.google.com!feeder1.cambriumusenet.nl!82.197.223.108.MISMATCH!feeder2.cambriumusenet.nl!feed.tweaknews.nl!216.40.29.245.MISMATCH!novia!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsgate.cuhk.edu.hk!goblin1!goblin.stu.neva.ru!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Numerical calculations: Why not use fixed point types for everything? Date: Mon, 04 Feb 2013 08:43:14 +0200 Organization: Tidorum Ltd Message-ID: References: <4905b963-0036-4129-8050-fb26ef0154d6@googlegroups.com> <32314026-23ae-45b8-a4c5-e589e7d79de2@googlegroups.com> <64e3c342-d042-40a2-8a16-b1f0cdff9f16@googlegroups.com> <91527f7c-0679-4c21-95c7-a07f3fff265d@googlegroups.com> <8cc51443-23f6-4736-a862-d0223998fc2e@googlegroups.com> <753a3719-e15f-4626-b3cc-ac76f7ef7499@googlegroups.com> <8ee504a6-b371-42ef-a91e-bbb70e3b81d8@googlegroups.com> Mime-Version: 1.0 X-Trace: individual.net vUtYJmIyQuQywDrcz+YKrQ0ZS8WHnvH1bXfncSZDfE4mcedqwbkJsBm8VBQo5AunWy Cancel-Lock: sha1:7tscHBbAYH/KiyN+CfmrZGbwL2g= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 In-Reply-To: <8ee504a6-b371-42ef-a91e-bbb70e3b81d8@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Date: 2013-02-04T08:43:14+02:00 List-Id: On 13-02-04 08:23 , Ada novice wrote: > On Sunday, February 3, 2013 5:05:22 AM UTC+1, Shark8 wrote: >> >> >> Type P is delta 0.1 digits 3 range 0.0..10.0; >> >> >> >> declare >> >> Index : P := P'First; >> >> begin >> >> loop >> >> Ada.Text_IO.Put_Line( Index'Img ); >> >> Exit when Index = P'Last; >> >> Index:= P'Succ(Index); >> >> End loop; >> >> end; >> > > I was working an example based on the working code you gave: > > with Ada.Text_IO; > with Ada.Long_Float_Text_IO; > > procedure Test is > > type P is delta 0.1 digits 3 range 0.0..10.0; > > Index: P := P'First; > Number : Long_Float := 100.0; > > > begin > loop > Ada.Text_IO.Put(Index'Img);Ada.Text_IO.Put(" "); > > Ada.Long_Float_Text_IO.Put (Item => Long_Float(Index)*Number, Fore => 3, Aft => 3, Exp => 0);Ada.Text_IO.Put(" "); > > --Number := Long_Float(Index)*Number; > Ada.Long_Float_Text_IO.Put (Item => Number, Fore => 3, Aft => 3, Exp => 0); > > Ada.Text_IO.New_Line; > > exit when Index = P'Last; > > Index := P'Succ(Index); > > > end loop; > > end Test; > > > On running I get: > > 0.0 0.000 100.000 > 0.1 10.000 100.000 > 0.2 20.000 100.000 > 0.3 30.000 100.000 > 0.4 40.000 100.000 > 0.5 50.000 100.000 > ... and so on > > which is expected. > > Now, when I un-comment the line > > --Number := Long_Float(Index)*Number; > > and run the code again, I get: > > 0.0 0.000 0.000 > 0.1 0.000 0.000 > 0.2 0.000 0.000 > 0.3 0.000 0.000 > 0.4 0.000 0.000 > 0.5 0.000 0.000 > > ... and so on. > > This is a weird behaviour. No, it is expected. > Why are the second and third columns all zeros now? On the first iteration of the loop, Index = 0.0. Therefore the uncommented statemement assigns the value Long_Float (0.0) * Number, which is zero, to Number. In the next iteration the same statement assigns Long_Float (0.1) * Number, which is again zero, to Number. So Number stays at zero throughout the loop. Perhaps you intended to assign a different variable? As in Number2 := Long_Float (Index) * Number; -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .