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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
/* This file is part of the KDE project
Copyright (C) 1998-2002 The KSpread Team
www.koffice.org/kspread
Copyright (C) 2005 Tomas Mecir <mecirt@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
// built-in trigonometric functions
#include "functions.h"
#include "valuecalc.h"
using namespace KSpread;
// prototypes (sort alphabetically)
Value func_acos (valVector args, ValueCalc *calc, FuncExtra *);
Value func_acosh (valVector args, ValueCalc *calc, FuncExtra *);
Value func_acot (valVector args, ValueCalc *calc, FuncExtra *);
Value func_asinh (valVector args, ValueCalc *calc, FuncExtra *);
Value func_asin (valVector args, ValueCalc *calc, FuncExtra *);
Value func_atan (valVector args, ValueCalc *calc, FuncExtra *);
Value func_atan2 (valVector args, ValueCalc *calc, FuncExtra *);
Value func_atanh (valVector args, ValueCalc *calc, FuncExtra *);
Value func_cos (valVector args, ValueCalc *calc, FuncExtra *);
Value func_cosh (valVector args, ValueCalc *calc, FuncExtra *);
Value func_degrees (valVector args, ValueCalc *calc, FuncExtra *);
Value func_radians (valVector args, ValueCalc *calc, FuncExtra *);
Value func_sin (valVector args, ValueCalc *calc, FuncExtra *);
Value func_sinh (valVector args, ValueCalc *calc, FuncExtra *);
Value func_tan (valVector args, ValueCalc *calc, FuncExtra *);
Value func_tanh (valVector args, ValueCalc *calc, FuncExtra *);
Value func_pi (valVector args, ValueCalc *calc, FuncExtra *);
// registers all trigonometric functions
void RegisterTrigFunctions()
{
FunctionRepository* repo = FunctionRepository::self();
Function *f;
f = new Function ("ACOS", func_acos);
repo->add (f);
f = new Function ("ACOSH", func_acosh);
repo->add (f);
f = new Function ("ACOT", func_acot);
repo->add (f);
f = new Function ("ASIN", func_asin);
repo->add (f);
f = new Function ("ASINH", func_asinh);
repo->add (f);
f = new Function ("ATAN", func_atan);
repo->add (f);
f = new Function ("ATAN2", func_atan2);
f->setParamCount (2);
repo->add (f);
f = new Function ("ATANH", func_atanh);
repo->add (f);
f = new Function ("COS", func_cos);
repo->add (f);
f = new Function ("COSH", func_cosh);
repo->add (f);
f = new Function ("DEGREES",func_degrees);
repo->add (f);
f = new Function ("RADIANS",func_radians);
repo->add (f);
f = new Function ("SIN", func_sin);
repo->add (f);
f = new Function ("SINH", func_sinh);
repo->add (f);
f = new Function ("TAN", func_tan);
repo->add (f);
f = new Function ("TANH", func_tanh);
repo->add (f);
f = new Function ("PI", func_pi);
f->setParamCount (0);
repo->add (f);
}
// Function: sin
Value func_sin (valVector args, ValueCalc *calc, FuncExtra *)
{
return calc->sin (args[0]);
}
// Function: cos
Value func_cos (valVector args, ValueCalc *calc, FuncExtra *)
{
return calc->cos (args[0]);
}
// Function: tan
Value func_tan (valVector args, ValueCalc *calc, FuncExtra *)
{
return calc->tg (args[0]);
}
// Function: atan
Value func_atan (valVector args, ValueCalc *calc, FuncExtra *)
{
return calc->atg (args[0]);
}
// Function: asin
Value func_asin (valVector args, ValueCalc *calc, FuncExtra *)
{
return calc->asin (args[0]);
}
// Function: acos
Value func_acos (valVector args, ValueCalc *calc, FuncExtra *)
{
return calc->acos (args[0]);
}
Value func_acot (valVector args, ValueCalc *calc, FuncExtra *)
{
// PI/2 - atg (val)
return calc->sub (calc->div (calc->pi(), 2), calc->atg (args[0]));
}
// Function: asinh
Value func_asinh (valVector args, ValueCalc *calc, FuncExtra *)
{
return calc->asinh (args[0]);
}
// Function: acosh
Value func_acosh (valVector args, ValueCalc *calc, FuncExtra *)
{
return calc->acosh (args[0]);
}
// Function: atanh
Value func_atanh (valVector args, ValueCalc *calc, FuncExtra *)
{
return calc->atgh (args[0]);
}
// Function: tanh
Value func_tanh (valVector args, ValueCalc *calc, FuncExtra *)
{
return calc->tgh (args[0]);
}
// Function: sinh
Value func_sinh (valVector args, ValueCalc *calc, FuncExtra *)
{
return calc->sinh (args[0]);
}
// Function: cosh
Value func_cosh (valVector args, ValueCalc *calc, FuncExtra *)
{
return calc->cosh (args[0]);
}
// Function: DEGREES
Value func_degrees (valVector args, ValueCalc *calc, FuncExtra *)
{
// val * 180 / pi
return calc->div (calc->mul (args[0], 180.0), calc->pi());
}
// Function: RADIANS
Value func_radians (valVector args, ValueCalc *calc, FuncExtra *)
{
// val * pi / 180
return calc->mul (calc->div (args[0], 180.0), calc->pi());
}
// Function: PI
Value func_pi (valVector, ValueCalc *calc, FuncExtra *)
{
return calc->pi();
}
// Function: atan2
Value func_atan2 (valVector args, ValueCalc *calc, FuncExtra *)
{
return calc->atan2 (args[1], args[0]);
}
|