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