This is atan2.c in view mode; [Download] [Up]
double jv_atan2(y,x)
double y,x;
{
/*
arctangent between -pi and pi.
*/
int sflag, piflag, pflag, qflag;
double z,sum,z2;
if ( y < 0 ) { y = -y; sflag = 1; }
else sflag = 0;
if ( x < 0 ) { x = -x; piflag = 1; }
else piflag = 0;
if ( y > x ) { pflag = 1; z = y; y = x; x = z; }
else pflag = 0;
/*
We are now in the range 0-1
*/
if ( y == 0 && x == 0 ) {
return(0);
}
if ( y > 0.2679491924311227065*x ) {
z = (y*1.7320508075688772935-x)/(y+1.7320508075688772935*x);
qflag = 1;
}
else {
z = y/x;
qflag = 0;
}
/*
Now we are in the range -(2-sqrt(3))<z<2-sqrt(3)
*/
z2 = z*z;
sum = z*( 0.99999999999999998493+z2*(
-0.33333333333329920123+z2*(
0.19999999998726326765+z2*(
-0.14285714102479574031+z2*(
0.11111097879199028445+z2*(
-0.09090370583742286501+z2*(
0.07679359531984028197+z2*(
-0.06483115238224471189+z2*(
0.04438679771995954480)))))))));
if ( qflag ) sum += 0.5235987755982988731;
if ( pflag ) sum = 1.5707963267948966192 - sum;
if ( piflag ) sum = 3.1415926535897932384 - sum;
if ( sflag ) sum = -sum;
return(sum);
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.