xref: /plan9/sys/src/libc/port/asin.c (revision 3e12c5d1bb89fc02707907988834ef147769ddaf)
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 <u.h>
9 #include <libc.h>
10 
11 double
asin(double arg)12 asin(double arg)
13 {
14 	double temp;
15 	int sign;
16 
17 	sign = 0;
18 	if(arg < 0) {
19 		arg = -arg;
20 		sign++;
21 	}
22 	if(arg > 1)
23 		return NaN();
24 	temp = sqrt(1 - arg*arg);
25 	if(arg > 0.7)
26 		temp = PIO2 - atan(temp/arg);
27 	else
28 		temp = atan(arg/temp);
29 	if(sign)
30 		temp = -temp;
31 	return temp;
32 }
33 
34 double
acos(double arg)35 acos(double arg)
36 {
37 	if(arg > 1 || arg < -1)
38 		return NaN();
39 	return PIO2 - asin(arg);
40 }
41