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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9b4538cfeb0c3576 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!l20g2000yqm.googlegroups.com!not-for-mail From: Henrique Newsgroups: comp.lang.ada Subject: Re: Float conversion Date: Fri, 30 Jul 2010 06:16:38 -0700 (PDT) Organization: http://groups.google.com Message-ID: <312f83b3-158e-4c21-8a8f-bea45762c6e7@l20g2000yqm.googlegroups.com> References: <9e669a3b-1013-4bd1-b372-5f7dfa46d083@f42g2000yqn.googlegroups.com> <1q5zc0ais535h$.1jqwfxhj9cflc$.dlg@40tude.net> <4c519968$0$6893$9b4e6d93@newsspool2.arcor-online.net> <1d1txn4x3r5xn.1trm4gx9n87gm$.dlg@40tude.net> <1jo4xj7cntwy1$.1ntf9smcka8vf$.dlg@40tude.net> NNTP-Posting-Host: 201.7.145.1 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1280495798 16279 127.0.0.1 (30 Jul 2010 13:16:38 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 30 Jul 2010 13:16:38 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l20g2000yqm.googlegroups.com; posting-host=201.7.145.1; posting-account=B_68zwoAAABo5d-uMxDzx4n-gXWKiMZT User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; OfficeLiveConnector.1.4; OfficeLivePatch.1.3),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:12715 Date: 2010-07-30T06:16:38-07:00 List-Id: Thanks for the help (everyone). By using this concept of intervals, I made the modifications in my code to solve the problem. On 29 jul, 16:15, "Dmitry A. Kazakov" wrote: > On Thu, 29 Jul 2010 11:21:52 -0700 (PDT), Henrique wrote: > > On Jul 29, 12:35=A0pm, "Dmitry A. Kazakov" > > wrote: > >> ------------------------ > >> var1 9.99900024414063E+02 > >> var4 9.99900085449219E+02 > > >> When rounded to 6 decimal digits both are same. But the underlying bas= e > >> binary type is longer than 6 digits. > > >> P.S. It is always useful to think of floating point numbers as interva= ls > >> (which they are) rather than numbers. > > >> -- > >> Regards, > >> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de > > > As I declared the type with 6 digits, I expected that it would make > > the comparison only for these digits (this would gave var4 =3D var1). > > No, the underlying base type is more or less free compiler choice. There > are certain rules, which in essence guarantee you accuracy of the basic > operations within the precision specified. > > > Do I always need to manually truncate the float number to the number > > of desired digits before making a comparison of them?? > > You should never use equality or inequality for floating-point types. The= y > do not have "physical" sense. As I said, floating-point numbers are > intervals. Two non-zero length [independent] intervals are *always* > unequal, even if their bounds are equal. > > > So what is the advantage of declaring it as "digits 6"? > > That the compiler guarantees you 6 decimal digits accuracy independently = on > whatever hardware you have. The idea behind of Ada numeric types is machi= ne > independence. You specify your requirements on the precision and range an= d > the compiler either gives you what you wanted or else rejects the program= . > > -- > Regards, > Dmitry A. Kazakovhttp://www.dmitry-kazakov.de- Ocultar texto das mensagen= s anteriores - > > - Mostrar texto das mensagens anteriores -