comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
Subject: Re: I think - it's a bug...
Date: Mon, 11 Mar 2002 07:43:03 -0600
Date: 2002-03-11T07:43:03-06:00	[thread overview]
Message-ID: <mailman.1015853822.21250.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: 3C8C41A8.B5D96800@yahoo.com

I think what happens when the put_line call is present is that the
C runtime library is called, which on NT can result in the
FPU unit state being changed, hence the desirability (or need) to
call GNAT.Float_Control.Reset, as suggested.

The statement from the UG _was_ included, and is:

In particular, if the Ada code will do any floating-point operations,
then the FPU must be setup in an appropriate manner. For the case
of the x86, for example, full precision mode is required. The
procedure GNAT.Float_Control.Reset may be used to ensure that
the FPU is in the right state.

----- Original Message -----
From: "Anatoly Chernyshev" <rhezusfactor@yahoo.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Sunday, March 10, 2002 11:33 PM
Subject: Re: I think - it's a bug...


>
>
> "David C. Hoos, Sr." wrote:
>
> > This is not a bug.  The problem comes about by not being aware of
> > the nature of floating point representation in computers.
> >
> > In your example, the value of dz (0.3) is not exactly representable in
> > binary -- it is an infinitely repeating binary fraction. Hence, all
values of
> > z that you compute are not exactly representable.
> >
> > Thus, if the value of dz was rounded upward to the next lsb when
> > converting from decimal to binary, all values of z will be slightly
> > larger than their true value.
> >
>
> That's true, but still, why inserting of "put_line
(float'image(1.0-(z/b)));"
> influences the behaviour of the program so much.
> Beyound that, I've got similar things with z=0.1 and 0.25. They were
solved
> though, by using different optomization levels (-O, -O2...).
>
>
> >
> > The only solution is to test the values of which you are about to take
> > the square root, and if the absolute value is less than some very small
> > threshold, set the value to 0.0.
> >
> > Alternatively, if you are sure (given the nature of the problem you
> > are solving) that z can never be greater than b, you could replace
> > (z/b) by Float'Min (1.0, z/b).
> >
> > Additionally, you might want to consider the following statement
> > from the GNAT User's Guide:
> > In particular, if the Ada code will do any floating-point operations,
> > then the FPU must be setup in an appropriate manner. For the case
> > of the x86, for example, full precision mode is required. The
> > procedure GNAT.Float_Control.Reset may be used to ensure that
> > the FPU is in the right state.
>
> > Finally you can obtain greater precision by using Long_Float or
Long_Long_Float
> > instead of Float.
>
> Thanks a lot for those suggestions (but you are omitted what is coming
from the
> GNAT UG).
>
> >
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>




  reply	other threads:[~2002-03-11 13:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-10  8:24 I think - it's a bug Anatoly Chernyshev
2002-03-10 12:58 ` David C. Hoos, Sr.
2002-03-11  5:33   ` Anatoly Chernyshev
2002-03-11 13:43     ` David C. Hoos [this message]
2002-03-11 16:13     ` Stephen Leake
2002-03-11  5:39   ` Jeffrey Carter
2002-03-11 14:53   ` Wes Groleau
2002-03-11 15:15     ` David C. Hoos
2002-03-11  5:32 ` Jeffrey Carter
2002-03-11  5:46   ` Anatoly Chernyshev
2002-03-11  8:19 ` Phil Thornley
2002-03-11 19:48 ` Anatoly Chernyshev
replies disabled

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