comp.lang.ada
 help / color / mirror / Atom feed
From: Ada novice <shai.lesh@gmx.com>
Cc: nma@12000.org
Subject: Re: Numerical calculations: Why not use fixed point types for everything?
Date: Sun, 3 Feb 2013 22:17:40 -0800 (PST)
Date: 2013-02-03T22:17:40-08:00	[thread overview]
Message-ID: <c81e7d23-8757-4a81-9ca2-d540afe0d819@googlegroups.com> (raw)
In-Reply-To: <kejv8v$4nq$1@speranza.aioe.org>

On Saturday, February 2, 2013 10:08:50 PM UTC+1, Nasser M. Abbasi wrote:

> 
> Well, it is common only in sloppy programming.
> 
> 
> 
> loop counters should always be discrete. as in integers,
> 

I do not think we should judge things too quickly. By having a "delta" that we can explicitly specify, this can make the code simpler to understand. Look at this code:

with Ada.Text_IO;             use Ada.Text_IO;
with Ada.Long_Float_Text_IO;  use Ada.Long_Float_Text_IO;

procedure Step_Freq is
   Count : Integer;
   Frequency : Long_Float;
   Frequency_Start : constant := -44.88;
   Frequency_Step  : constant := (67.32 - Frequency_Start) / 299.0;
   Delta_Frequency : Long_Float;

 begin
   Count := 0;
   Frequency := Frequency_Start;
   for I in 1..300 loop
       Frequency := Frequency_Start + Frequency_Step * Long_Float (I - 1);
       if I = 2 then
          Delta_Frequency := abs(Frequency - Frequency_Start);
          Put (Item => Delta_Frequency, Fore => 3, Aft => 5, Exp => 0); Put("  ");
          Put (Item => Frequency_Step, Fore => 3, Aft => 5, Exp => 0);
          New_Line;
       end if;
       Count := Count + 1;
   end loop;
    Put_Line ("Count after loop is" & Integer'Image (Count));
    New_Line;
    Put (Item => Frequency, Fore => 3, Aft => 3, Exp => 0);
end Step_Freq;

Well, I am using a discrete loop counter. But is this the best way to go about for such a simple example? What if I want the Frequency_Step to take a specific value? Then I will have perhaps to play with the range and the amount of discrete points I need in order to arrive at a desired Frequency_Step in the code. So why not use fixed-point for the frequency as we know exactly what step we want?

Thanks.
YC



  reply	other threads:[~2013-02-04  6:17 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
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 [this message]
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