[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 !!!)