aboutsummaryrefslogtreecommitdiff
path: root/src/base/math/asin.c
blob: 4687715deae318fab2c2f9317202a45c2c95c311 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * asin(arg) and acos(arg) return the arcsin, arccos,
 * respectively of their arguments.
 *
 * Arctan is called after appropriate range reduction.
 */

#include <u.h>
#include <base.h>

double
math·asin(double arg)
{
	double temp;
	int sign;

	sign = 0;
	if(arg < 0) {
		arg = -arg;
		sign++;
	}
	if(arg > 1)
		return math·NaN();
	temp = math·sqrt(1 - arg*arg);
	if(arg > 0.7)
		temp = math·PIO2 - math·atan(temp/arg);
	else
		temp = math·atan(arg/temp);
	if(sign)
		temp = -temp;
	return temp;
}

double
math·acos(double arg)
{
	if(arg > 1 || arg < -1)
		return math·NaN();
	return math·PIO2 - math·asin(arg);
}