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