1*9b5730f6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9b5730f6SAndrew Rist * distributed with this work for additional information 6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance 9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an 15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the 17*9b5730f6SAndrew Rist * specific language governing permissions and limitations 18*9b5730f6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9b5730f6SAndrew Rist *************************************************************/ 21*9b5730f6SAndrew Rist 22*9b5730f6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <cmath> 28cdf0e10cSrcweir #include "file/FNumericFunctions.hxx" 29cdf0e10cSrcweir #include <rtl/math.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir using namespace connectivity; 32cdf0e10cSrcweir using namespace connectivity::file; 33cdf0e10cSrcweir //------------------------------------------------------------------ 34cdf0e10cSrcweir ORowSetValue OOp_Abs::operate(const ORowSetValue& lhs) const 35cdf0e10cSrcweir { 36cdf0e10cSrcweir if ( lhs.isNull() ) 37cdf0e10cSrcweir return lhs; 38cdf0e10cSrcweir 39cdf0e10cSrcweir double nVal(lhs); 40cdf0e10cSrcweir if ( nVal < 0 ) 41cdf0e10cSrcweir nVal *= -1.0; 42cdf0e10cSrcweir return fabs(nVal); 43cdf0e10cSrcweir } 44cdf0e10cSrcweir //------------------------------------------------------------------ 45cdf0e10cSrcweir ORowSetValue OOp_Sign::operate(const ORowSetValue& lhs) const 46cdf0e10cSrcweir { 47cdf0e10cSrcweir if ( lhs.isNull() ) 48cdf0e10cSrcweir return lhs; 49cdf0e10cSrcweir 50cdf0e10cSrcweir sal_Int32 nRet = 0; 51cdf0e10cSrcweir double nVal(lhs); 52cdf0e10cSrcweir if ( nVal < 0 ) 53cdf0e10cSrcweir nRet = -1; 54cdf0e10cSrcweir else if ( nVal > 0 ) 55cdf0e10cSrcweir nRet = 1; 56cdf0e10cSrcweir 57cdf0e10cSrcweir return nRet; 58cdf0e10cSrcweir } 59cdf0e10cSrcweir //------------------------------------------------------------------ 60cdf0e10cSrcweir ORowSetValue OOp_Mod::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const 61cdf0e10cSrcweir { 62cdf0e10cSrcweir if ( lhs.isNull() || rhs.isNull() ) 63cdf0e10cSrcweir return ORowSetValue(); 64cdf0e10cSrcweir 65cdf0e10cSrcweir return fmod((double)lhs,(double)rhs); 66cdf0e10cSrcweir } 67cdf0e10cSrcweir //------------------------------------------------------------------ 68cdf0e10cSrcweir ORowSetValue OOp_Floor::operate(const ORowSetValue& lhs) const 69cdf0e10cSrcweir { 70cdf0e10cSrcweir if ( lhs.isNull() ) 71cdf0e10cSrcweir return lhs; 72cdf0e10cSrcweir 73cdf0e10cSrcweir return floor((double)lhs); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir // ----------------------------------------------------------------------------- 76cdf0e10cSrcweir ORowSetValue OOp_Ceiling::operate(const ORowSetValue& lhs) const 77cdf0e10cSrcweir { 78cdf0e10cSrcweir if ( lhs.isNull() ) 79cdf0e10cSrcweir return lhs; 80cdf0e10cSrcweir 81cdf0e10cSrcweir double nVal(lhs); 82cdf0e10cSrcweir return ceil(nVal); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir // ----------------------------------------------------------------------------- 85cdf0e10cSrcweir ORowSetValue OOp_Round::operate(const ::std::vector<ORowSetValue>& lhs) const 86cdf0e10cSrcweir { 87cdf0e10cSrcweir if ( lhs.empty() || lhs.size() > 2 ) 88cdf0e10cSrcweir return ORowSetValue(); 89cdf0e10cSrcweir 90cdf0e10cSrcweir size_t nSize = lhs.size(); 91cdf0e10cSrcweir double nVal = lhs[nSize-1]; 92cdf0e10cSrcweir 93cdf0e10cSrcweir sal_Int32 nDec = 0; 94cdf0e10cSrcweir if ( nSize == 2 && !lhs[0].isNull() ) 95cdf0e10cSrcweir nDec = lhs[0]; 96cdf0e10cSrcweir return ::rtl::math::round(nVal,nDec); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir // ----------------------------------------------------------------------------- 99cdf0e10cSrcweir ORowSetValue OOp_Exp::operate(const ORowSetValue& lhs) const 100cdf0e10cSrcweir { 101cdf0e10cSrcweir if ( lhs.isNull() ) 102cdf0e10cSrcweir return lhs; 103cdf0e10cSrcweir 104cdf0e10cSrcweir double nVal(lhs); 105cdf0e10cSrcweir return exp(nVal); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir // ----------------------------------------------------------------------------- 108cdf0e10cSrcweir ORowSetValue OOp_Ln::operate(const ORowSetValue& lhs) const 109cdf0e10cSrcweir { 110cdf0e10cSrcweir if ( lhs.isNull() || static_cast<double>(lhs) < 0.0 ) 111cdf0e10cSrcweir return lhs; 112cdf0e10cSrcweir 113cdf0e10cSrcweir double nVal(lhs); 114cdf0e10cSrcweir nVal = log(nVal); 115cdf0e10cSrcweir if ( rtl::math::isNan(nVal) ) 116cdf0e10cSrcweir return ORowSetValue(); 117cdf0e10cSrcweir return nVal; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir // ----------------------------------------------------------------------------- 120cdf0e10cSrcweir ORowSetValue OOp_Log::operate(const ::std::vector<ORowSetValue>& lhs) const 121cdf0e10cSrcweir { 122cdf0e10cSrcweir if ( lhs.empty() || lhs.size() > 2 ) 123cdf0e10cSrcweir return ORowSetValue(); 124cdf0e10cSrcweir size_t nSize = lhs.size(); 125cdf0e10cSrcweir double nVal = log( (double)lhs[nSize-1] ); 126cdf0e10cSrcweir 127cdf0e10cSrcweir 128cdf0e10cSrcweir if ( nSize == 2 && !lhs[0].isNull() ) 129cdf0e10cSrcweir nVal /= log((double)lhs[0]); 130cdf0e10cSrcweir 131cdf0e10cSrcweir if ( rtl::math::isNan(nVal) ) 132cdf0e10cSrcweir return ORowSetValue(); 133cdf0e10cSrcweir return nVal; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir // ----------------------------------------------------------------------------- 136cdf0e10cSrcweir ORowSetValue OOp_Log10::operate(const ORowSetValue& lhs) const 137cdf0e10cSrcweir { 138cdf0e10cSrcweir if ( lhs.isNull() || static_cast<double>(lhs) < 0.0 ) 139cdf0e10cSrcweir return lhs; 140cdf0e10cSrcweir 141cdf0e10cSrcweir double nVal = log((double)lhs); 142cdf0e10cSrcweir if ( rtl::math::isNan(nVal) ) 143cdf0e10cSrcweir return ORowSetValue(); 144cdf0e10cSrcweir nVal /= log(10.0); 145cdf0e10cSrcweir return nVal; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir // ----------------------------------------------------------------------------- 148cdf0e10cSrcweir ORowSetValue OOp_Pow::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const 149cdf0e10cSrcweir { 150cdf0e10cSrcweir if ( lhs.isNull() || rhs.isNull() ) 151cdf0e10cSrcweir return lhs; 152cdf0e10cSrcweir 153cdf0e10cSrcweir return pow((double)lhs,(double)rhs); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir //------------------------------------------------------------------ 156cdf0e10cSrcweir ORowSetValue OOp_Sqrt::operate(const ORowSetValue& lhs) const 157cdf0e10cSrcweir { 158cdf0e10cSrcweir if ( lhs.isNull() ) 159cdf0e10cSrcweir return lhs; 160cdf0e10cSrcweir 161cdf0e10cSrcweir double nVal = sqrt((double)lhs); 162cdf0e10cSrcweir if ( rtl::math::isNan(nVal) ) 163cdf0e10cSrcweir return ORowSetValue(); 164cdf0e10cSrcweir return nVal; 165cdf0e10cSrcweir } 166cdf0e10cSrcweir // ----------------------------------------------------------------------------- 167cdf0e10cSrcweir ORowSetValue OOp_Pi::operate(const ::std::vector<ORowSetValue>& /*lhs*/) const 168cdf0e10cSrcweir { 169cdf0e10cSrcweir return 3.141592653589793116; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir // ----------------------------------------------------------------------------- 172cdf0e10cSrcweir ORowSetValue OOp_Cos::operate(const ORowSetValue& lhs) const 173cdf0e10cSrcweir { 174cdf0e10cSrcweir if ( lhs.isNull() ) 175cdf0e10cSrcweir return lhs; 176cdf0e10cSrcweir 177cdf0e10cSrcweir return cos((double)lhs); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir // ----------------------------------------------------------------------------- 180cdf0e10cSrcweir ORowSetValue OOp_Sin::operate(const ORowSetValue& lhs) const 181cdf0e10cSrcweir { 182cdf0e10cSrcweir if ( lhs.isNull() ) 183cdf0e10cSrcweir return lhs; 184cdf0e10cSrcweir 185cdf0e10cSrcweir return sin((double)lhs); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir // ----------------------------------------------------------------------------- 188cdf0e10cSrcweir ORowSetValue OOp_Tan::operate(const ORowSetValue& lhs) const 189cdf0e10cSrcweir { 190cdf0e10cSrcweir if ( lhs.isNull() ) 191cdf0e10cSrcweir return lhs; 192cdf0e10cSrcweir 193cdf0e10cSrcweir return tan((double)lhs); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir // ----------------------------------------------------------------------------- 196cdf0e10cSrcweir ORowSetValue OOp_ACos::operate(const ORowSetValue& lhs) const 197cdf0e10cSrcweir { 198cdf0e10cSrcweir if ( lhs.isNull() ) 199cdf0e10cSrcweir return lhs; 200cdf0e10cSrcweir 201cdf0e10cSrcweir return acos((double)lhs); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir // ----------------------------------------------------------------------------- 204cdf0e10cSrcweir ORowSetValue OOp_ASin::operate(const ORowSetValue& lhs) const 205cdf0e10cSrcweir { 206cdf0e10cSrcweir if ( lhs.isNull() ) 207cdf0e10cSrcweir return lhs; 208cdf0e10cSrcweir 209cdf0e10cSrcweir return asin((double)lhs); 210cdf0e10cSrcweir } 211cdf0e10cSrcweir // ----------------------------------------------------------------------------- 212cdf0e10cSrcweir ORowSetValue OOp_ATan::operate(const ORowSetValue& lhs) const 213cdf0e10cSrcweir { 214cdf0e10cSrcweir if ( lhs.isNull() ) 215cdf0e10cSrcweir return lhs; 216cdf0e10cSrcweir 217cdf0e10cSrcweir return atan((double)lhs); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir // ----------------------------------------------------------------------------- 220cdf0e10cSrcweir ORowSetValue OOp_ATan2::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const 221cdf0e10cSrcweir { 222cdf0e10cSrcweir if ( lhs.isNull() || rhs.isNull() ) 223cdf0e10cSrcweir return lhs; 224cdf0e10cSrcweir 225cdf0e10cSrcweir return atan2((double)lhs,(double)rhs); 226cdf0e10cSrcweir } 227cdf0e10cSrcweir // ----------------------------------------------------------------------------- 228cdf0e10cSrcweir ORowSetValue OOp_Degrees::operate(const ORowSetValue& lhs) const 229cdf0e10cSrcweir { 230cdf0e10cSrcweir if ( lhs.isNull() ) 231cdf0e10cSrcweir return lhs; 232cdf0e10cSrcweir 233cdf0e10cSrcweir double nLhs = lhs; 234cdf0e10cSrcweir return nLhs*180*(1.0/3.141592653589793116); 235cdf0e10cSrcweir } 236cdf0e10cSrcweir // ----------------------------------------------------------------------------- 237cdf0e10cSrcweir ORowSetValue OOp_Radians::operate(const ORowSetValue& lhs) const 238cdf0e10cSrcweir { 239cdf0e10cSrcweir if ( lhs.isNull() ) 240cdf0e10cSrcweir return lhs; 241cdf0e10cSrcweir 242cdf0e10cSrcweir double nLhs = lhs; 243cdf0e10cSrcweir return nLhs*3.141592653589793116*(1.0/180.0); 244cdf0e10cSrcweir } 245cdf0e10cSrcweir // ----------------------------------------------------------------------------- 246