bug-gnubg
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnubg] compiling with optimization


From: Jon Kinsey
Subject: Re: [Bug-gnubg] compiling with optimization
Date: Thu, 20 Nov 2003 10:06:06 +0000

At 17:15 19/11/2003, Jim Segrave wrote:
[snip]
Hmm - I have an email from Olivier Baur:

On Tue 19 Aug 2003 (18:14 +0200), Olivier Baur wrote:
> Le mardi, 19 ao? 2003, ? 15:34 Europe/Paris, Jim Segrave a ?crit :
>
> >I must be missing something here: sin(pi/2) = 1
> >
> >latitude = (float)sin(angle2) * lip;
> >
> >so latitude = lip
> >new_radius = (float)sqrt((lip * lip) - (latitude * latitude));
> >so
> >new_radius = (float) sqrt(lip*lip - lip*lip) =
> >should be sqrt( 0 ), except for rouding errors, but should never lead
> >to NAN.
> >
> >The only way I can see this going wrong is some compiler optimisation
> >causing problems for the FPU. Could you try the following patch which
> >should give an assert failure (and hence should allow a debugger to
> >see the values in question):
>
> Well, you were right, it is an optimisation issue -- the problem
> disappears when I compile with -O0.
>
> I've added some debug-code to the proc to see what arg is passed to
> sqrt, writing:
>
>   float d2;
>   latitude = (float)sin(angle2) * lip;
>   d2 = (lip * lip) - (latitude * latitude);
>   new_radius = (float)sqrt(d2);
>
> With -O0 I get what expected:
>
>   latitude = 1.500000e-02
>   lip = 1.500000e-02
>   d2 = 0.000000e+00
>
> But with -O2 I get:
>
>   latitude = 1.500000e-02
>   lip = 1.500000e-02
>   d2 = -7.194467e-12  (!!! negative, nonzero !!!)

The problem was a rounding issue with sqrt(0) being replaced with sqrt(small negative number). I added a fix for this. I guess the floating point operations were done in a different order or in a different way with the optimizations on.

Anyway if Olivier is around perhaps he can confirm which settings he has.

Jon





reply via email to

[Prev in Thread] Current Thread [Next in Thread]