xref: /trunk/main/connectivity/source/inc/file/FNumericFunctions.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _CONNECTIVITY_FILE_FNUMERICFUNCTIONS_HXX_
29 #define _CONNECTIVITY_FILE_FNUMERICFUNCTIONS_HXX_
30 
31 #include "file/fcode.hxx"
32 #include "file/filedllapi.hxx"
33 
34 namespace connectivity
35 {
36     class OSQLParseNode;
37     namespace file
38     {
39         /** ABS(X)
40             Returns the absolute value of X:
41 
42         > SELECT ABS(2);
43                 -> 2
44         > SELECT ABS(-32);
45                 -> 32
46 
47         */
48         class OOp_Abs : public OUnaryOperator
49         {
50         protected:
51             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
52         };
53 
54         /** SIGN(X)
55             Returns the sign of the argument as -1, 0, or 1, depending on whether X is negative, zero, or positive:
56 
57             > SELECT SIGN(-32);
58                     -> -1
59             > SELECT SIGN(0);
60                     -> 0
61             > SELECT SIGN(234);
62                     -> 1
63 
64         */
65         class OOp_Sign : public OUnaryOperator
66         {
67         protected:
68             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
69         };
70 
71         /** MOD(N,M)
72             %
73                 Modulo (like the % operator in C). Returns the remainder of N divided by M:
74 
75             > SELECT MOD(234, 10);
76                     -> 4
77             > SELECT 253 % 7;
78                     -> 1
79             > SELECT MOD(29,9);
80                     -> 2
81             > SELECT 29 MOD 9;
82                     -> 2
83         */
84         class OOp_Mod : public OBinaryOperator
85         {
86         protected:
87             virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const;
88         };
89 
90         /** FLOOR(X)
91             Returns the largest integer value not greater than X:
92 
93         > SELECT FLOOR(1.23);
94                 -> 1
95         > SELECT FLOOR(-1.23);
96                 -> -2
97 
98         */
99         class OOp_Floor : public OUnaryOperator
100         {
101         protected:
102             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
103         };
104 
105         /** CEILING(X)
106             Returns the smallest integer value not less than X:
107 
108         > SELECT CEILING(1.23);
109                 -> 2
110         > SELECT CEILING(-1.23);
111                 -> -1
112 
113         */
114         class OOp_Ceiling : public OUnaryOperator
115         {
116         protected:
117             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
118         };
119 
120         /** ROUND(X)
121             ROUND(X,D)
122             Returns the argument X, rounded to the nearest integer. With two arguments rounded to a number to D decimals.
123 
124             > SELECT ROUND(-1.23);
125                     -> -1
126             > SELECT ROUND(-1.58);
127                     -> -2
128             > SELECT ROUND(1.58);
129                     -> 2
130             > SELECT ROUND(1.298, 1);
131                     -> 1.3
132             > SELECT ROUND(1.298, 0);
133                     -> 1
134             > SELECT ROUND(23.298, -1);
135                     -> 20
136         */
137         class OOp_Round : public ONthOperator
138         {
139         protected:
140             virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const;
141         };
142 
143         /** EXP(X)
144             Returns the value of e (the base of natural logarithms) raised to the power of X:
145 
146         > SELECT EXP(2);
147                 -> 7.389056
148         > SELECT EXP(-2);
149                 -> 0.135335
150         */
151         class OOp_Exp : public OUnaryOperator
152         {
153         protected:
154             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
155         };
156 
157         /** LN(X)
158             Returns the natural logarithm of X:
159 
160         > SELECT LN(2);
161                 -> 0.693147
162         > SELECT LN(-2);
163                 -> NULL
164 
165         */
166         class OOp_Ln : public OUnaryOperator
167         {
168         protected:
169             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
170         };
171 
172         /** LOG(X)
173             LOG(B,X)
174                 If called with one parameter, this function returns the natural logarithm of X:
175 
176             > SELECT LOG(2);
177                     -> 0.693147
178             > SELECT LOG(-2);
179                     -> NULL
180 
181                 If called with two parameters, this function returns the logarithm of X for an arbitary base B:
182 
183             > SELECT LOG(2,65536);
184                     -> 16.000000
185             > SELECT LOG(1,100);
186                     -> NULL
187         */
188         class OOp_Log : public ONthOperator
189         {
190         protected:
191             virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const;
192         };
193 
194         /** LOG10(X)
195             Returns the base-10 logarithm of X:
196 
197         > SELECT LOG10(2);
198                 -> 0.301030
199         > SELECT LOG10(100);
200                 -> 2.000000
201         > SELECT LOG10(-100);
202                 -> NULL
203         */
204         class OOp_Log10 : public OUnaryOperator
205         {
206         protected:
207             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
208         };
209 
210         /** POWER(X,Y)
211                 Returns the value of X raised to the power of Y:
212 
213             > SELECT POW(2,2);
214                     -> 4.000000
215             > SELECT POW(2,-2);
216                     -> 0.250000
217         */
218         class OOp_Pow : public OBinaryOperator
219         {
220         protected:
221             virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const;
222         };
223 
224         /** SQRT(X)
225             Returns the non-negative square root of X:
226 
227         > SELECT SQRT(4);
228                 -> 2.000000
229         > SELECT SQRT(20);
230                 -> 4.472136
231         */
232         class OOp_Sqrt : public OUnaryOperator
233         {
234         protected:
235             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
236         };
237 
238         /** PI()
239             Returns the value of PI. The default shown number of decimals is 5, but  internally uses the full double precession for PI.
240 
241         > SELECT PI();
242                 -> 3.141593
243         > SELECT PI()+0.000000000000000000;
244                 -> 3.141592653589793116
245 
246         */
247         class OOp_Pi : public ONthOperator
248         {
249         protected:
250             virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const;
251         };
252 
253         /** COS(X)
254             Returns the cosine of X, where X is given in radians:
255 
256         > SELECT COS(PI());
257                 -> -1.000000
258         */
259         class OOp_Cos : public OUnaryOperator
260         {
261         protected:
262             virtual ORowSetValue operate(const ORowSetValue& lhs = ORowSetValue()) const;
263         };
264 
265         /** SIN(X)
266             Returns the sine of X, where X is given in radians:
267 
268         > SELECT SIN(PI());
269                 -> 0.000000
270 
271         */
272         class OOp_Sin : public OUnaryOperator
273         {
274         protected:
275             virtual ORowSetValue operate(const ORowSetValue& lhs = ORowSetValue()) const;
276         };
277         /** TAN(X)
278             Returns the tangent of X, where X is given in radians:
279 
280         > SELECT TAN(PI()+1);
281                 -> 1.557408
282         */
283         class OOp_Tan : public OUnaryOperator
284         {
285         protected:
286             virtual ORowSetValue operate(const ORowSetValue& lhs = ORowSetValue()) const;
287         };
288 
289         /** ACOS(X)
290             Returns the arc cosine of X, that is, the value whose cosine is X. Returns NULL if X is not in the range -1 to 1:
291 
292         > SELECT ACOS(1);
293                 -> 0.000000
294         > SELECT ACOS(1.0001);
295                 -> NULL
296         > SELECT ACOS(0);
297                 -> 1.570796
298         */
299         class OOp_ACos : public OUnaryOperator
300         {
301         protected:
302             virtual ORowSetValue operate(const ORowSetValue& lhs = ORowSetValue()) const;
303         };
304 
305         /** ASIN(X)
306             Returns the arc sine of X, that is, the value whose sine is X. Returns NULL if X is not in the range -1 to 1:
307 
308         > SELECT ASIN(0.2);
309                 -> 0.201358
310         > SELECT ASIN('foo');
311                 -> 0.000000
312         */
313         class OOp_ASin : public OUnaryOperator
314         {
315         protected:
316             virtual ORowSetValue operate(const ORowSetValue& lhs = ORowSetValue()) const;
317         };
318 
319         /** ATAN(X)
320             Returns the arc tangent of X, that is, the value whose tangent is X:
321 
322         > SELECT ATAN(2);
323                 -> 1.107149
324         > SELECT ATAN(-2);
325                 -> -1.107149
326         */
327         class OOp_ATan : public OUnaryOperator
328         {
329         protected:
330             virtual ORowSetValue operate(const ORowSetValue& lhs = ORowSetValue()) const;
331         };
332 
333         /** ATAN2(Y,X)
334             Returns the arc tangent of the two variables X and Y. It is similar to calculating the arc tangent of Y / X, except that the signs of both arguments are used to determine the quadrant of the result:
335 
336         > SELECT ATAN2(-2,2);
337                 -> -0.785398
338         > SELECT ATAN2(PI(),0);
339                 -> 1.570796
340 
341         */
342         class OOp_ATan2 : public OBinaryOperator
343         {
344         protected:
345             virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const;
346         };
347 
348         /** DEGREES(X)
349             Returns the argument X, converted from radians to degrees:
350 
351         > SELECT DEGREES(PI());
352                 -> 180.000000
353         */
354         class OOp_Degrees : public OUnaryOperator
355         {
356         protected:
357             virtual ORowSetValue operate(const ORowSetValue& lhs = ORowSetValue()) const;
358         };
359 
360         /** RADIANS(X)
361             Returns the argument X, converted from degrees to radians:
362 
363         > SELECT RADIANS(90);
364                 -> 1.570796
365 
366         */
367         class OOp_Radians : public OUnaryOperator
368         {
369         protected:
370             virtual ORowSetValue operate(const ORowSetValue& lhs = ORowSetValue()) const;
371         };
372     }
373 }
374 
375 #endif // _CONNECTIVITY_FILE_FNUMERICFUNCTIONS_HXX_
376 
377