xref: /plan9-contrib/sys/src/ape/lib/ap/math/asin.c (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
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.570796326794896619;
12 
13 double
14 asin(double arg)
15 {
16 	double sign, temp;
17 
18 	sign = 1;
19 	if(arg < 0) {
20 		arg = -arg;
21 		sign = -1;
22 	}
23 
24 	if(arg > 1) {
25 		errno = EDOM;
26 		return 0;
27 	}
28 
29 	temp = sqrt(1 - arg*arg);
30 	if(arg > 0.7)
31 		temp = pio2 - atan(temp/arg);
32 	else
33 		temp = atan(arg/temp);
34 
35 	return sign*temp;
36 }
37 
38 double
39 acos(double arg)
40 {
41 	if(arg > 1 || arg < -1) {
42 		errno = EDOM;
43 		return 0;
44 	}
45 	return pio2 - asin(arg);
46 }
47