comp.lang.ada
 help / color / mirror / Atom feed
From: Henrique <henriquemagalhaes@gmail.com>
Subject: Re: Float conversion
Date: Fri, 30 Jul 2010 06:16:38 -0700 (PDT)
Date: 2010-07-30T06:16:38-07:00	[thread overview]
Message-ID: <312f83b3-158e-4c21-8a8f-bea45762c6e7@l20g2000yqm.googlegroups.com> (raw)
In-Reply-To: 1jo4xj7cntwy1$.1ntf9smcka8vf$.dlg@40tude.net

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" <mail...@dmitry-kazakov.de>
wrote:
> On Thu, 29 Jul 2010 11:21:52 -0700 (PDT), Henrique wrote:
> > On Jul 29, 12:35 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> > wrote:
> >> ------------------------
> >> var1 9.99900024414063E+02
> >> var4 9.99900085449219E+02
>
> >> When rounded to 6 decimal digits both are same. But the underlying base
> >> binary type is longer than 6 digits.
>
> >> P.S. It is always useful to think of floating point numbers as intervals
> >> (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 = 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. They
> 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 machine
> independence. You specify your requirements on the precision and range and
> the compiler either gives you what you wanted or else rejects the program.
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de- Ocultar texto das mensagens anteriores -
>
> - Mostrar texto das mensagens anteriores -




  parent reply	other threads:[~2010-07-30 13:16 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-29 12:23 Float conversion Henrique
2010-07-29 12:44 ` Jacob Sparre Andersen
2010-07-29 12:46 ` Dmitry A. Kazakov
2010-07-29 15:08   ` Georg Bauhaus
2010-07-29 15:10     ` Georg Bauhaus
2010-07-29 15:35     ` Dmitry A. Kazakov
2010-07-29 18:21       ` Henrique
2010-07-29 19:08         ` Jeffrey R. Carter
2010-07-29 19:15         ` Dmitry A. Kazakov
2010-07-30  1:30           ` Phil Clayton
2010-07-30  8:43             ` Dmitry A. Kazakov
2010-07-30 13:14               ` Phil Clayton
2010-07-30 14:34                 ` Dmitry A. Kazakov
2010-07-31 15:12                 ` Stephen Leake
2010-08-03  1:07                   ` Phil Clayton
2010-08-03  3:31                     ` Shark8
2010-08-03 10:38                     ` Georg Bauhaus
2010-08-04  7:27                       ` Stephen Leake
2010-08-04 16:15                         ` Georg Bauhaus
2010-08-04 16:32                       ` Phil Clayton
2010-08-04  7:26                     ` Stephen Leake
2010-08-04 12:52                       ` Robert A Duff
2010-08-04 14:32                         ` Dmitry A. Kazakov
2010-08-04 19:36                           ` Simon Wright
2010-08-04 19:46                             ` Dmitry A. Kazakov
2010-08-04 20:29                             ` Georg Bauhaus
2010-08-05 12:05                         ` Stephen Leake
2010-08-07  5:54                           ` Shark8
2010-08-07  8:56                             ` Georg Bauhaus
2010-08-07 13:49                               ` Shark8
2010-08-05 10:20                       ` Phil Clayton
2010-07-30 13:16           ` Henrique [this message]
2010-07-29 15:37   ` Warren
2010-07-29 14:56 ` Georg Bauhaus
2010-07-29 17:56   ` Jeffrey R. Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox