LCOV - code coverage report
Current view: top level - libreoffice/connectivity/source/drivers/file - FNumericFunctions.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 121 0.0 %
Date: 2012-12-27 Functions: 0 22 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include <cmath>
      22             : #include "file/FNumericFunctions.hxx"
      23             : #include <rtl/math.hxx>
      24             : 
      25             : using namespace connectivity;
      26             : using namespace connectivity::file;
      27             : //------------------------------------------------------------------
      28           0 : ORowSetValue OOp_Abs::operate(const ORowSetValue& lhs) const
      29             : {
      30           0 :     if ( lhs.isNull() )
      31           0 :         return lhs;
      32             : 
      33           0 :     double nVal(lhs);
      34           0 :     if ( nVal < 0 )
      35           0 :         nVal *= -1.0;
      36           0 :     return fabs(nVal);
      37             : }
      38             : //------------------------------------------------------------------
      39           0 : ORowSetValue OOp_Sign::operate(const ORowSetValue& lhs) const
      40             : {
      41           0 :     if ( lhs.isNull() )
      42           0 :         return lhs;
      43             : 
      44           0 :     sal_Int32 nRet = 0;
      45           0 :     double nVal(lhs);
      46           0 :     if ( nVal < 0 )
      47           0 :         nRet = -1;
      48           0 :     else if ( nVal > 0 )
      49           0 :         nRet = 1;
      50             : 
      51           0 :     return nRet;
      52             : }
      53             : //------------------------------------------------------------------
      54           0 : ORowSetValue OOp_Mod::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
      55             : {
      56           0 :     if ( lhs.isNull() || rhs.isNull() )
      57           0 :         return ORowSetValue();
      58             : 
      59           0 :     return fmod((double)lhs,(double)rhs);
      60             : }
      61             : //------------------------------------------------------------------
      62           0 : ORowSetValue OOp_Floor::operate(const ORowSetValue& lhs) const
      63             : {
      64           0 :     if ( lhs.isNull() )
      65           0 :         return lhs;
      66             : 
      67           0 :     return floor((double)lhs);
      68             : }
      69             : // -----------------------------------------------------------------------------
      70           0 : ORowSetValue OOp_Ceiling::operate(const ORowSetValue& lhs) const
      71             : {
      72           0 :     if ( lhs.isNull() )
      73           0 :         return lhs;
      74             : 
      75           0 :     double nVal(lhs);
      76           0 :     return ceil(nVal);
      77             : }
      78             : // -----------------------------------------------------------------------------
      79           0 : ORowSetValue OOp_Round::operate(const ::std::vector<ORowSetValue>& lhs) const
      80             : {
      81           0 :     if ( lhs.empty() || lhs.size() > 2 )
      82           0 :         return ORowSetValue();
      83             : 
      84           0 :     size_t nSize = lhs.size();
      85           0 :     double nVal = lhs[nSize-1];
      86             : 
      87           0 :     sal_Int32 nDec = 0;
      88           0 :     if ( nSize == 2 && !lhs[0].isNull() )
      89           0 :         nDec = lhs[0];
      90           0 :     return ::rtl::math::round(nVal,nDec);
      91             : }
      92             : // -----------------------------------------------------------------------------
      93           0 : ORowSetValue OOp_Exp::operate(const ORowSetValue& lhs) const
      94             : {
      95           0 :     if ( lhs.isNull() )
      96           0 :         return lhs;
      97             : 
      98           0 :     double nVal(lhs);
      99           0 :     return exp(nVal);
     100             : }
     101             : // -----------------------------------------------------------------------------
     102           0 : ORowSetValue OOp_Ln::operate(const ORowSetValue& lhs) const
     103             : {
     104           0 :     if ( lhs.isNull() || static_cast<double>(lhs) < 0.0 )
     105           0 :         return lhs;
     106             : 
     107           0 :     double nVal(lhs);
     108           0 :     nVal = log(nVal);
     109           0 :     if ( rtl::math::isNan(nVal) )
     110           0 :         return ORowSetValue();
     111           0 :     return nVal;
     112             : }
     113             : // -----------------------------------------------------------------------------
     114           0 : ORowSetValue OOp_Log::operate(const ::std::vector<ORowSetValue>& lhs) const
     115             : {
     116           0 :     if ( lhs.empty() || lhs.size() > 2 )
     117           0 :         return ORowSetValue();
     118           0 :     size_t nSize = lhs.size();
     119           0 :     double nVal = log( (double)lhs[nSize-1] );
     120             : 
     121             : 
     122           0 :     if ( nSize == 2 && !lhs[0].isNull() )
     123           0 :         nVal /= log((double)lhs[0]);
     124             : 
     125           0 :     if ( rtl::math::isNan(nVal) )
     126           0 :         return ORowSetValue();
     127           0 :     return nVal;
     128             : }
     129             : // -----------------------------------------------------------------------------
     130           0 : ORowSetValue OOp_Log10::operate(const ORowSetValue& lhs) const
     131             : {
     132           0 :     if ( lhs.isNull() || static_cast<double>(lhs) < 0.0 )
     133           0 :         return lhs;
     134             : 
     135           0 :     double nVal = log((double)lhs);
     136           0 :     if ( rtl::math::isNan(nVal) )
     137           0 :         return ORowSetValue();
     138           0 :     nVal /= log(10.0);
     139           0 :     return nVal;
     140             : }
     141             : // -----------------------------------------------------------------------------
     142           0 : ORowSetValue OOp_Pow::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
     143             : {
     144           0 :     if ( lhs.isNull() || rhs.isNull() )
     145           0 :         return lhs;
     146             : 
     147           0 :     return pow((double)lhs,(double)rhs);
     148             : }
     149             : //------------------------------------------------------------------
     150           0 : ORowSetValue OOp_Sqrt::operate(const ORowSetValue& lhs) const
     151             : {
     152           0 :     if ( lhs.isNull() )
     153           0 :         return lhs;
     154             : 
     155           0 :     double nVal = sqrt((double)lhs);
     156           0 :     if ( rtl::math::isNan(nVal) )
     157           0 :         return ORowSetValue();
     158           0 :     return nVal;
     159             : }
     160             : // -----------------------------------------------------------------------------
     161           0 : ORowSetValue OOp_Pi::operate(const ::std::vector<ORowSetValue>& /*lhs*/) const
     162             : {
     163           0 :     return 3.141592653589793116;
     164             : }
     165             : // -----------------------------------------------------------------------------
     166           0 : ORowSetValue OOp_Cos::operate(const ORowSetValue& lhs) const
     167             : {
     168           0 :     if ( lhs.isNull() )
     169           0 :         return lhs;
     170             : 
     171           0 :     return cos((double)lhs);
     172             : }
     173             : // -----------------------------------------------------------------------------
     174           0 : ORowSetValue OOp_Sin::operate(const ORowSetValue& lhs) const
     175             : {
     176           0 :     if ( lhs.isNull() )
     177           0 :         return lhs;
     178             : 
     179           0 :     return sin((double)lhs);
     180             : }
     181             : // -----------------------------------------------------------------------------
     182           0 : ORowSetValue OOp_Tan::operate(const ORowSetValue& lhs) const
     183             : {
     184           0 :     if ( lhs.isNull() )
     185           0 :         return lhs;
     186             : 
     187           0 :     return tan((double)lhs);
     188             : }
     189             : // -----------------------------------------------------------------------------
     190           0 : ORowSetValue OOp_ACos::operate(const ORowSetValue& lhs) const
     191             : {
     192           0 :     if ( lhs.isNull() )
     193           0 :         return lhs;
     194             : 
     195           0 :     return acos((double)lhs);
     196             : }
     197             : // -----------------------------------------------------------------------------
     198           0 : ORowSetValue OOp_ASin::operate(const ORowSetValue& lhs) const
     199             : {
     200           0 :     if ( lhs.isNull() )
     201           0 :         return lhs;
     202             : 
     203           0 :     return asin((double)lhs);
     204             : }
     205             : // -----------------------------------------------------------------------------
     206           0 : ORowSetValue OOp_ATan::operate(const ORowSetValue& lhs) const
     207             : {
     208           0 :     if ( lhs.isNull() )
     209           0 :         return lhs;
     210             : 
     211           0 :     return atan((double)lhs);
     212             : }
     213             : // -----------------------------------------------------------------------------
     214           0 : ORowSetValue OOp_ATan2::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
     215             : {
     216           0 :     if ( lhs.isNull() || rhs.isNull() )
     217           0 :         return lhs;
     218             : 
     219           0 :     return atan2((double)lhs,(double)rhs);
     220             : }
     221             : // -----------------------------------------------------------------------------
     222           0 : ORowSetValue OOp_Degrees::operate(const ORowSetValue& lhs) const
     223             : {
     224           0 :     if ( lhs.isNull() )
     225           0 :         return lhs;
     226             : 
     227           0 :     double nLhs = lhs;
     228           0 :     return nLhs*180*(1.0/3.141592653589793116);
     229             : }
     230             : // -----------------------------------------------------------------------------
     231           0 : ORowSetValue OOp_Radians::operate(const ORowSetValue& lhs) const
     232             : {
     233           0 :     if ( lhs.isNull() )
     234           0 :         return lhs;
     235             : 
     236           0 :     double nLhs = lhs;
     237           0 :     return nLhs*3.141592653589793116*(1.0/180.0);
     238             : }
     239             : // -----------------------------------------------------------------------------
     240             : 
     241             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10