forked from libtom/libtomfloat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmpf_asin.c
48 lines (40 loc) · 900 Bytes
/
mpf_asin.c
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
41
42
43
44
45
46
47
#include <tomfloat.h>
/*
( x )
asin(x) = 2 atan( ------------------ )
( 1 + sqrt(1 -x^2) )
*/
int mpf_asin(mp_float * a, mp_float * b)
{
int err;
mp_float one, t;
err = MP_OKAY;
if ((err = mpf_init_multi(a->radix, &one, &t, NULL)) != MP_OKAY) {
return err;
}
if ((err = mpf_const_d(&one, 1)) != MP_OKAY) {
goto _ERR;
}
if ((err = mpf_sqr(a, &t)) != MP_OKAY) {
goto _ERR;
}
if ((err = mpf_sub(&one, &t, &t)) != MP_OKAY) {
goto _ERR;
}
if ((err = mpf_sqrt(&t, &t)) != MP_OKAY) {
goto _ERR;
}
if ((err = mpf_add(&one, &t, &t)) != MP_OKAY) {
goto _ERR;
}
if ((err = mpf_div(a, &t, &t)) != MP_OKAY) {
goto _ERR;
}
if ((err = mpf_atan(&t, b)) != MP_OKAY) {
goto _ERR;
}
b->exp += 1;
_ERR:
mpf_clear_multi(&one, &t, NULL);
return err;
}