cid#1607171 Data race condition
[LibreOffice.git] / connectivity / source / inc / file / FNumericFunctions.hxx
blob765f2cde82231c57fe30fdf8b91eb5cc358c42b4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <file/fcode.hxx>
24 namespace connectivity::file
26 /** ABS(X)
27 Returns the absolute value of X:
29 > SELECT ABS(2);
30 -> 2
31 > SELECT ABS(-32);
32 -> 32
35 class OOp_Abs : public OUnaryOperator
37 protected:
38 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
41 /** SIGN(X)
42 Returns the sign of the argument as -1, 0, or 1, depending on whether X is negative, zero, or positive:
44 > SELECT SIGN(-32);
45 -> -1
46 > SELECT SIGN(0);
47 -> 0
48 > SELECT SIGN(234);
49 -> 1
52 class OOp_Sign : public OUnaryOperator
54 protected:
55 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
58 /** MOD(N,M)
60 Modulo (like the % operator in C). Returns the remainder of N divided by M:
62 > SELECT MOD(234, 10);
63 -> 4
64 > SELECT 253 % 7;
65 -> 1
66 > SELECT MOD(29,9);
67 -> 2
68 > SELECT 29 MOD 9;
69 -> 2
71 class OOp_Mod : public OBinaryOperator
73 protected:
74 virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const override;
77 /** FLOOR(X)
78 Returns the largest integer value not greater than X:
80 > SELECT FLOOR(1.23);
81 -> 1
82 > SELECT FLOOR(-1.23);
83 -> -2
86 class OOp_Floor : public OUnaryOperator
88 protected:
89 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
92 /** CEILING(X)
93 Returns the smallest integer value not less than X:
95 > SELECT CEILING(1.23);
96 -> 2
97 > SELECT CEILING(-1.23);
98 -> -1
101 class OOp_Ceiling : public OUnaryOperator
103 protected:
104 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
107 /** ROUND(X)
108 ROUND(X,D)
109 Returns the argument X, rounded to the nearest integer. With two arguments rounded to a number to D decimals.
111 > SELECT ROUND(-1.23);
112 -> -1
113 > SELECT ROUND(-1.58);
114 -> -2
115 > SELECT ROUND(1.58);
116 -> 2
117 > SELECT ROUND(1.298, 1);
118 -> 1.3
119 > SELECT ROUND(1.298, 0);
120 -> 1
121 > SELECT ROUND(23.298, -1);
122 -> 20
124 class OOp_Round : public ONthOperator
126 protected:
127 virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override;
130 /** EXP(X)
131 Returns the value of e (the base of natural logarithms) raised to the power of X:
133 > SELECT EXP(2);
134 -> 7.389056
135 > SELECT EXP(-2);
136 -> 0.135335
138 class OOp_Exp : public OUnaryOperator
140 protected:
141 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
144 /** LN(X)
145 Returns the natural logarithm of X:
147 > SELECT LN(2);
148 -> 0.693147
149 > SELECT LN(-2);
150 -> NULL
153 class OOp_Ln : public OUnaryOperator
155 protected:
156 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
159 /** LOG(X)
160 LOG(B,X)
161 If called with one parameter, this function returns the natural logarithm of X:
163 > SELECT LOG(2);
164 -> 0.693147
165 > SELECT LOG(-2);
166 -> NULL
168 If called with two parameters, this function returns the logarithm of X for an arbitrary base B:
170 > SELECT LOG(2,65536);
171 -> 16.000000
172 > SELECT LOG(1,100);
173 -> NULL
175 class OOp_Log : public ONthOperator
177 protected:
178 virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override;
181 /** LOG10(X)
182 Returns the base-10 logarithm of X:
184 > SELECT LOG10(2);
185 -> 0.301030
186 > SELECT LOG10(100);
187 -> 2.000000
188 > SELECT LOG10(-100);
189 -> NULL
191 class OOp_Log10 : public OUnaryOperator
193 protected:
194 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
197 /** POWER(X,Y)
198 Returns the value of X raised to the power of Y:
200 > SELECT POW(2,2);
201 -> 4.000000
202 > SELECT POW(2,-2);
203 -> 0.250000
205 class OOp_Pow : public OBinaryOperator
207 protected:
208 virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const override;
211 /** SQRT(X)
212 Returns the non-negative square root of X:
214 > SELECT SQRT(4);
215 -> 2.000000
216 > SELECT SQRT(20);
217 -> 4.472136
219 class OOp_Sqrt : public OUnaryOperator
221 protected:
222 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
225 /** PI()
226 Returns the value of PI. The default shown number of decimals is 5, but internally uses the full double precision for PI.
228 > SELECT PI();
229 -> 3.141593
230 > SELECT PI()+0.000000000000000000;
231 -> 3.141592653589793238
234 class OOp_Pi : public ONthOperator
236 protected:
237 virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override;
240 /** COS(X)
241 Returns the cosine of X, where X is given in radians:
243 > SELECT COS(PI());
244 -> -1.000000
246 class OOp_Cos : public OUnaryOperator
248 protected:
249 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
252 /** SIN(X)
253 Returns the sine of X, where X is given in radians:
255 > SELECT SIN(PI());
256 -> 0.000000
259 class OOp_Sin : public OUnaryOperator
261 protected:
262 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
264 /** TAN(X)
265 Returns the tangent of X, where X is given in radians:
267 > SELECT TAN(PI()+1);
268 -> 1.557408
270 class OOp_Tan : public OUnaryOperator
272 protected:
273 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
276 /** ACOS(X)
277 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:
279 > SELECT ACOS(1);
280 -> 0.000000
281 > SELECT ACOS(1.0001);
282 -> NULL
283 > SELECT ACOS(0);
284 -> 1.570796
286 class OOp_ACos : public OUnaryOperator
288 protected:
289 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
292 /** ASIN(X)
293 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:
295 > SELECT ASIN(0.2);
296 -> 0.201358
297 > SELECT ASIN('foo');
298 -> 0.000000
300 class OOp_ASin : public OUnaryOperator
302 protected:
303 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
306 /** ATAN(X)
307 Returns the arc tangent of X, that is, the value whose tangent is X:
309 > SELECT ATAN(2);
310 -> 1.107149
311 > SELECT ATAN(-2);
312 -> -1.107149
314 class OOp_ATan : public OUnaryOperator
316 protected:
317 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
320 /** ATAN2(Y,X)
321 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:
323 > SELECT ATAN2(-2,2);
324 -> -0.785398
325 > SELECT ATAN2(PI(),0);
326 -> 1.570796
329 class OOp_ATan2 : public OBinaryOperator
331 protected:
332 virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const override;
335 /** DEGREES(X)
336 Returns the argument X, converted from radians to degrees:
338 > SELECT DEGREES(PI());
339 -> 180.000000
341 class OOp_Degrees : public OUnaryOperator
343 protected:
344 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
347 /** RADIANS(X)
348 Returns the argument X, converted from degrees to radians:
350 > SELECT RADIANS(90);
351 -> 1.570796
354 class OOp_Radians : public OUnaryOperator
356 protected:
357 virtual ORowSetValue operate(const ORowSetValue& lhs) const override;
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */