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