/* Arcsine and arccosine calculation. Uses Arctan() and Sqroot() as 
   external calls. 

   int Arcsin(float *a,float x);
       x - argument,
       a - pointer to result
   Returns error code NORMAL or EDOM

   int Arccos(float *a,float x);
       x - argument,
       a - pointer to result
   Returns error code NORMAL or EDOM

*/

#define M_PI ((float)3.141592653589793)
#define M_PI2 (M_PI/2.F)

enum{NORMAL,EDOM};

extern float Arctan(float x);
extern float Sqroot(float x);

int Arcsin(float *a,float x) {
 /* check for exceptions */
 if(x<-1.F) {*a=-M_PI2;return(EDOM);}
 if(x==-1.F) {*a=-M_PI2;return(NORMAL);}
 if(x>1.F) {*a=M_PI2;return(EDOM);}
 if(x==1.F) {*a=M_PI2;return(NORMAL);}
 /* transform the argument */
 x/=Sqroot(1.F-x*x);
 *a=Arctan(x);
 return(NORMAL);
}

int Arccos(float *a,float x) {
 int re=Arcsin(a,x);
 *a=M_PI2-(*a);
 return(re);
}