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.110.68 with SMTP id m4mr10980901qap.2.1359958661031; Sun, 03 Feb 2013 22:17:41 -0800 (PST) X-Received: by 10.49.94.143 with SMTP id dc15mr1617919qeb.32.1359958661011; Sun, 03 Feb 2013 22:17:41 -0800 (PST) Path: k2ni4456qap.0!nntp.google.com!p13no8749887qai.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 3 Feb 2013 22:17:40 -0800 (PST) In-Reply-To: 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> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Numerical calculations: Why not use fixed point types for everything? From: Ada novice Cc: nma@12000.org Injection-Date: Mon, 04 Feb 2013 06:17:41 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2013-02-03T22:17:40-08:00 List-Id: On Saturday, February 2, 2013 10:08:50 PM UTC+1, Nasser M. Abbasi wrote: >=20 > Well, it is common only in sloppy programming. >=20 >=20 >=20 > loop counters should always be discrete. as in integers, >=20 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. L= ook 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 :=3D -44.88; Frequency_Step : constant :=3D (67.32 - Frequency_Start) / 299.0; Delta_Frequency : Long_Float; begin Count :=3D 0; Frequency :=3D Frequency_Start; for I in 1..300 loop Frequency :=3D Frequency_Start + Frequency_Step * Long_Float (I - 1)= ; if I =3D 2 then Delta_Frequency :=3D abs(Frequency - Frequency_Start); Put (Item =3D> Delta_Frequency, Fore =3D> 3, Aft =3D> 5, Exp =3D>= 0); Put(" "); Put (Item =3D> Frequency_Step, Fore =3D> 3, Aft =3D> 5, Exp =3D> = 0); New_Line; end if; Count :=3D Count + 1; end loop; Put_Line ("Count after loop is" & Integer'Image (Count)); New_Line; Put (Item =3D> Frequency, Fore =3D> 3, Aft =3D> 3, Exp =3D> 0); end Step_Freq; Well, I am using a discrete loop counter. But is this the best way to go ab= out 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 amo= unt of discrete points I need in order to arrive at a desired Frequency_Ste= p in the code. So why not use fixed-point for the frequency as we know exac= tly what step we want? Thanks. YC