From: Ada novice <shai.lesh@gmx.com>
Subject: Re: Numerical calculations: Why not use fixed point types for everything?
Date: Sun, 3 Feb 2013 22:23:55 -0800 (PST)
Date: 2013-02-03T22:23:55-08:00 [thread overview]
Message-ID: <8ee504a6-b371-42ef-a91e-bbb70e3b81d8@googlegroups.com> (raw)
In-Reply-To: <753a3719-e15f-4626-b3cc-ac76f7ef7499@googlegroups.com>
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
next prev parent reply other threads:[~2013-02-04 6:23 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-17 10:33 Numerical calculations: Why not use fixed point types for everything? Ada novice
2013-01-17 14:40 ` Nasser M. Abbasi
2013-01-17 16:16 ` Adam Beneschan
2013-01-17 17:00 ` Georg Bauhaus
2013-01-17 16:25 ` Adam Beneschan
2013-01-18 9:17 ` Ada novice
2013-01-18 17:24 ` J-P. Rosen
2013-01-18 17:52 ` Jeffrey Carter
2013-01-18 18:15 ` Dennis Lee Bieber
2013-01-18 18:59 ` Adam Beneschan
2013-01-19 4:41 ` Dennis Lee Bieber
2013-01-19 6:26 ` Jeffrey Carter
2013-01-19 14:14 ` Robert A Duff
2013-01-25 12:16 ` Paul Colin Gloster
2013-01-24 10:55 ` Ada novice
2013-01-24 11:47 ` Simon Wright
2013-01-24 14:21 ` Ada novice
2013-01-20 0:05 ` Robin Vowels
2013-01-18 23:06 ` Robin Vowels
2013-01-18 19:09 ` Adam Beneschan
2013-01-18 21:39 ` Randy Brukardt
2013-01-19 7:02 ` Ada novice
2013-01-25 12:09 ` Paul Colin Gloster
2013-01-25 12:23 ` Paul Colin Gloster
2013-01-28 9:09 ` Ada novice
2013-02-01 10:53 ` Ada novice
2013-02-01 15:01 ` Shark8
2013-02-02 18:55 ` Ada novice
2013-02-03 4:05 ` Shark8
2013-02-04 6:23 ` Ada novice [this message]
2013-02-04 6:43 ` Niklas Holsti
2013-02-04 7:27 ` Ada novice
2013-02-04 9:37 ` Niklas Holsti
2013-02-04 10:09 ` Ada novice
2013-02-04 14:24 ` Niklas Holsti
2013-02-04 16:44 ` Jeffrey Carter
2013-02-04 21:12 ` Niklas Holsti
2013-02-04 17:31 ` Robert A Duff
2013-02-04 21:20 ` Niklas Holsti
2013-02-02 21:08 ` Nasser M. Abbasi
2013-02-04 6:17 ` Ada novice
2013-02-05 2:27 ` Randy Brukardt
2013-02-06 7:11 ` Ada novice
2013-02-07 6:03 ` Randy Brukardt
2013-02-07 8:43 ` Shark8
2013-02-08 3:17 ` Randy Brukardt
2013-02-08 6:20 ` Ada novice
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox