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: 103376,548c38bb2d3e1bb6 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!p3g2000yqp.googlegroups.com!not-for-mail From: Ada novice Newsgroups: comp.lang.ada Subject: Re: understanding floating point types Date: Sun, 22 Aug 2010 12:05:33 -0700 (PDT) Organization: http://groups.google.com Message-ID: <2d2a622b-6c4a-45b7-9e3c-a565d5dbc9e3@p3g2000yqp.googlegroups.com> References: <74406fc1-f64b-4a3e-9dd6-301f1ed467ab@w30g2000yqw.googlegroups.com> <7b0ca24f-4a5e-43a9-9f71-e4adffb98694@q1g2000yqg.googlegroups.com> <37d8fbc1-fdaf-4ca9-9393-6163f2e3fa2e@s9g2000yqd.googlegroups.com> NNTP-Posting-Host: 193.11.22.91 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1282503933 23789 127.0.0.1 (22 Aug 2010 19:05:33 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 22 Aug 2010 19:05:33 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p3g2000yqp.googlegroups.com; posting-host=193.11.22.91; posting-account=Rr9I-QoAAACS-nOzpA-mGxtAlZ46Nb6I User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:13626 Date: 2010-08-22T12:05:33-07:00 List-Id: On Aug 22, 8:16=A0pm, "Dmitry A. Kazakov" wrote: > On Sun, 22 Aug 2010 10:15:24 -0700 (PDT), Ada novice wrote: > > I didn't quite get this part. In my previous example with say a =3D 2.3= 3 > > and b =3D 3.45. Does Multiplication of a with b mean converting each of > > a and b in model number first and then do the multiplication and > > afterwards approximating the result to the nearest model number? Or > > the multiplication will just be performed with the two numbers as 2.33 > > X 3.45 =3D 8.0385 and then approximating this result to the nearest > > model number? > > No, the result is 8.0385 (assuming 32-bit machine numbers). Try this: > > with Ada.Text_IO; use Ada.Text_IO; > procedure Test_Float is > =A0 =A0type My_Float is digits 3; > =A0 =A0X : My_Float :=3D 2.33; > =A0 =A0Y : My_Float :=3D 3.45; > begin > =A0 =A0Put_Line ("Model view:" & My_Float'Image (X*Y)); > =A0 =A0Put_Line ("The reality:" & Float'Image (Float (X*Y))); > end Test_Float; > > It should print: > > Model view: 8.04E+00 > The reality: 8.03850E+00 > > When you print the number using My_Float'Image that rounds the machine > number to the nearest model number. In computations and conversions > machine numbers are left untouched. > > -- > Regards, > Dmitry A. Kazakovhttp://www.dmitry-kazakov.de Thanks for all this information. I have 2 small queries: 1. You used: type My_Float is digits 3; I tend to confuse the fact that digits 3 means 3 digits of precision after the decimal point? So when I consider 2.33 or 3.45, then both numbers are with digits 2 in my mind. Or does digits 3 mean 3 significant digits which will include the leading 2 in 2.33 and the leading 3 in 3.45 as well? 2. In your example, you have: Model view: 8.04E+00 The reality: 8.03850E+00 If I understand correctly, model view represents the number that is exactly representable by the computer. In our case here, we can get the reality number since Float has higher precision digits than My_Float. However if My_float used the same precision digits as Float (i.e. 6) then this would also represent the number that could be represented by the computer. If both a and b had a hypothetical 30 digits of precision, then neither Float (6 digits) nor Long_Float (15 digits), nor Long_Long_Float (18 digits) would give the right value that would represent the model number of the multiplication result a*b. I mentioned the word hypothetical, as we would not able to use a number with 30 digits of precision anyway on a computer. But my point was to say that Model view doesn't have to have less precision digits as the reality number. But in our example, since My_Float has fewer digits than Float, in this specific case we can form the reality number with more precision digits than the model number. Thanks, YC