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,FREEMAIL_FROM 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.224.175.65 with SMTP id w1mr10985001qaz.7.1359959035299; Sun, 03 Feb 2013 22:23:55 -0800 (PST) X-Received: by 10.49.62.2 with SMTP id u2mr1622787qer.38.1359959035279; Sun, 03 Feb 2013 22:23:55 -0800 (PST) Path: k2ni4456qap.0!nntp.google.com!p13no8759974qai.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 3 Feb 2013 22:23:55 -0800 (PST) In-Reply-To: <753a3719-e15f-4626-b3cc-ac76f7ef7499@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=130.240.232.139; posting-account=Rr9I-QoAAACS-nOzpA-mGxtAlZ46Nb6I NNTP-Posting-Host: 130.240.232.139 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> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <8ee504a6-b371-42ef-a91e-bbb70e3b81d8@googlegroups.com> Subject: Re: Numerical calculations: Why not use fixed point types for everything? From: Ada novice Injection-Date: Mon, 04 Feb 2013 06:23:55 +0000 Content-Type: text/plain; charset=ISO-8859-1 Date: 2013-02-03T22:23:55-08:00 List-Id: 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. Why are the second and third columns all zeros now? Thanks. YC