5
* Copyright (C) 2000 - 2007 Michael C. Ring
7
* Permission to use, copy, and distribute this software and its
8
* documentation for any purpose with or without fee is hereby granted,
9
* provided that the above copyright notice appear in all copies and
10
* that both that copyright notice and this permission notice appear
11
* in supporting documentation.
13
* Permission to modify the software is granted. Permission to distribute
14
* the modified code is granted. Modifications are to be distributed by
15
* using the file 'license.txt' as a template to modify the file header.
16
* 'license.txt' is available in the official MAPM distribution.
18
* This software is provided "as is" without express or implied warranty.
23
* This file contains the 'ARC' family of functions; ARC-SIN,
24
* ARC-COS, ARC-TAN when the input arg is very close to 0 (zero).
29
#include "pgscript/utilities/mapm-lib/m_apm_lc.h"
31
/****************************************************************************/
33
Calculate arcsin using the identity :
36
arcsin (x) == arctan [ --------------- ]
40
void M_arcsin_near_0(M_APM rr, int places, M_APM aa)
44
tmp5 = M_get_stack_var();
45
tmp6 = M_get_stack_var();
47
M_cos_to_sin(tmp5, (places + 8), aa);
48
m_apm_divide(tmp6, (places + 8), aa, tmp5);
49
M_arctan_near_0(rr, places, tmp6);
53
/****************************************************************************/
55
Calculate arccos using the identity :
57
arccos (x) == PI / 2 - arcsin (x)
60
void M_arccos_near_0(M_APM rr, int places, M_APM aa)
64
tmp1 = M_get_stack_var();
65
tmp2 = M_get_stack_var();
67
M_check_PI_places(places);
68
M_arcsin_near_0(tmp1, (places + 4), aa);
69
m_apm_subtract(tmp2, MM_lc_HALF_PI, tmp1);
70
m_apm_round(rr, places, tmp2);
74
/****************************************************************************/
76
calculate arctan (x) with the following series:
79
arctan (x) = x - --- + --- - --- + --- ...
83
void M_arctan_near_0(M_APM rr, int places, M_APM aa)
85
M_APM tmp0, tmp2, tmpR, tmpS, digit, term;
86
int tolerance, dplaces, local_precision;
89
tmp0 = M_get_stack_var();
90
tmp2 = M_get_stack_var();
91
tmpR = M_get_stack_var();
92
tmpS = M_get_stack_var();
93
term = M_get_stack_var();
94
digit = M_get_stack_var();
96
tolerance = aa->m_apm_exponent - (places + 4);
97
dplaces = (places + 8) - aa->m_apm_exponent;
100
m_apm_copy(tmpS, aa);
101
m_apm_multiply(tmp0, aa, aa);
102
m_apm_round(tmp2, (dplaces + 8), tmp0);
109
* do the subtraction term
112
m_apm_multiply(tmp0, term, tmp2);
114
if ((tmp0->m_apm_exponent < tolerance) || (tmp0->m_apm_sign == 0))
116
m_apm_round(rr, places, tmpS);
120
local_precision = dplaces + tmp0->m_apm_exponent;
122
if (local_precision < 20)
123
local_precision = 20;
126
m_apm_set_long(digit, m1);
127
m_apm_round(term, local_precision, tmp0);
128
m_apm_divide(tmp0, local_precision, term, digit);
129
m_apm_subtract(tmpR, tmpS, tmp0);
132
* do the addition term
135
m_apm_multiply(tmp0, term, tmp2);
137
if ((tmp0->m_apm_exponent < tolerance) || (tmp0->m_apm_sign == 0))
139
m_apm_round(rr, places, tmpR);
143
local_precision = dplaces + tmp0->m_apm_exponent;
145
if (local_precision < 20)
146
local_precision = 20;
149
m_apm_set_long(digit, m1);
150
m_apm_round(term, local_precision, tmp0);
151
m_apm_divide(tmp0, local_precision, term, digit);
152
m_apm_add(tmpS, tmpR, tmp0);
155
M_restore_stack(6); /* restore the 6 locals we used here */
157
/****************************************************************************/