1 /* 2 asin(arg) and acos(arg) return the arcsin, arccos, 3 respectively of their arguments. 4 5 Arctan is called after appropriate range reduction. 6 */ 7 8 #include <math.h> 9 #include <errno.h> 10 11 static double pio2 = 1.570796326794896619231e0; 12 13 double asin(double arg)14asin(double arg) 15 { 16 double temp; 17 int sign; 18 19 sign = 0; 20 if(arg < 0) { 21 arg = -arg; 22 sign++; 23 } 24 if(arg > 1) { 25 errno = EDOM; 26 return 0; 27 } 28 temp = sqrt(1 - arg*arg); 29 if(arg > 0.7) 30 temp = pio2 - atan(temp/arg); 31 else 32 temp = atan(arg/temp); 33 34 if(sign) 35 temp = -temp; 36 return temp; 37 } 38 39 double acos(double arg)40acos(double arg) 41 { 42 if(arg > 1 || arg < -1) { 43 errno = EDOM; 44 return 0; 45 } 46 return pio2 - asin(arg); 47 } 48