nss: upgrade to release 3.73
[LibreOffice.git] / connectivity / source / drivers / file / FNumericFunctions.cxx
bloba6784a55c140ddb13b472abe40b0db70cfe4ac5d
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 .
21 #include <cmath>
22 #include <file/FNumericFunctions.hxx>
23 #include <rtl/math.hxx>
25 using namespace connectivity;
26 using namespace connectivity::file;
28 const double fPi = 3.14159265358979323846;
30 ORowSetValue OOp_Abs::operate(const ORowSetValue& lhs) const
32 if ( lhs.isNull() )
33 return lhs;
35 double nVal(lhs);
36 if ( nVal < 0 )
37 nVal *= -1.0;
38 return fabs(nVal);
41 ORowSetValue OOp_Sign::operate(const ORowSetValue& lhs) const
43 if ( lhs.isNull() )
44 return lhs;
46 sal_Int32 nRet = 0;
47 double nVal(lhs);
48 if ( nVal < 0 )
49 nRet = -1;
50 else if ( nVal > 0 )
51 nRet = 1;
53 return nRet;
56 ORowSetValue OOp_Mod::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
58 if ( lhs.isNull() || rhs.isNull() )
59 return ORowSetValue();
61 return fmod(static_cast<double>(lhs),static_cast<double>(rhs));
64 ORowSetValue OOp_Floor::operate(const ORowSetValue& lhs) const
66 if ( lhs.isNull() )
67 return lhs;
69 return floor(static_cast<double>(lhs));
72 ORowSetValue OOp_Ceiling::operate(const ORowSetValue& lhs) const
74 if ( lhs.isNull() )
75 return lhs;
77 double nVal(lhs);
78 return ceil(nVal);
81 ORowSetValue OOp_Round::operate(const std::vector<ORowSetValue>& lhs) const
83 if ( lhs.empty() || lhs.size() > 2 )
84 return ORowSetValue();
86 size_t nSize = lhs.size();
87 double nVal = lhs[nSize-1];
89 sal_Int32 nDec = 0;
90 if ( nSize == 2 && !lhs[0].isNull() )
91 nDec = lhs[0];
92 return ::rtl::math::round(nVal,nDec);
95 ORowSetValue OOp_Exp::operate(const ORowSetValue& lhs) const
97 if ( lhs.isNull() )
98 return lhs;
100 double nVal(lhs);
101 return exp(nVal);
104 ORowSetValue OOp_Ln::operate(const ORowSetValue& lhs) const
106 if ( lhs.isNull() || static_cast<double>(lhs) < 0.0 )
107 return lhs;
109 double nVal(lhs);
110 nVal = log(nVal);
111 if ( std::isnan(nVal) )
112 return ORowSetValue();
113 return nVal;
116 ORowSetValue OOp_Log::operate(const std::vector<ORowSetValue>& lhs) const
118 if ( lhs.empty() || lhs.size() > 2 )
119 return ORowSetValue();
120 size_t nSize = lhs.size();
121 double nVal = log( static_cast<double>(lhs[nSize-1]) );
124 if ( nSize == 2 && !lhs[0].isNull() )
125 nVal /= log(static_cast<double>(lhs[0]));
127 if ( std::isnan(nVal) )
128 return ORowSetValue();
129 return nVal;
132 ORowSetValue OOp_Log10::operate(const ORowSetValue& lhs) const
134 if ( lhs.isNull() || static_cast<double>(lhs) < 0.0 )
135 return lhs;
137 double nVal = log(static_cast<double>(lhs));
138 if ( std::isnan(nVal) )
139 return ORowSetValue();
140 nVal /= log(10.0);
141 return nVal;
144 ORowSetValue OOp_Pow::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
146 if ( lhs.isNull() || rhs.isNull() )
147 return lhs;
149 return pow(static_cast<double>(lhs),static_cast<double>(rhs));
152 ORowSetValue OOp_Sqrt::operate(const ORowSetValue& lhs) const
154 if ( lhs.isNull() )
155 return lhs;
157 double nVal = sqrt(static_cast<double>(lhs));
158 if ( std::isnan(nVal) )
159 return ORowSetValue();
160 return nVal;
163 ORowSetValue OOp_Pi::operate(const std::vector<ORowSetValue>& /*lhs*/) const
165 return fPi;
168 ORowSetValue OOp_Cos::operate(const ORowSetValue& lhs) const
170 if ( lhs.isNull() )
171 return lhs;
173 return cos(static_cast<double>(lhs));
176 ORowSetValue OOp_Sin::operate(const ORowSetValue& lhs) const
178 if ( lhs.isNull() )
179 return lhs;
181 return sin(static_cast<double>(lhs));
184 ORowSetValue OOp_Tan::operate(const ORowSetValue& lhs) const
186 if ( lhs.isNull() )
187 return lhs;
189 return tan(static_cast<double>(lhs));
192 ORowSetValue OOp_ACos::operate(const ORowSetValue& lhs) const
194 if ( lhs.isNull() )
195 return lhs;
197 return acos(static_cast<double>(lhs));
200 ORowSetValue OOp_ASin::operate(const ORowSetValue& lhs) const
202 if ( lhs.isNull() )
203 return lhs;
205 return asin(static_cast<double>(lhs));
208 ORowSetValue OOp_ATan::operate(const ORowSetValue& lhs) const
210 if ( lhs.isNull() )
211 return lhs;
213 return atan(static_cast<double>(lhs));
216 ORowSetValue OOp_ATan2::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
218 if ( lhs.isNull() || rhs.isNull() )
219 return lhs;
221 return atan2(static_cast<double>(lhs),static_cast<double>(rhs));
224 ORowSetValue OOp_Degrees::operate(const ORowSetValue& lhs) const
226 if ( lhs.isNull() )
227 return lhs;
229 double nLhs = lhs;
230 return nLhs*180*(1.0/fPi);
233 ORowSetValue OOp_Radians::operate(const ORowSetValue& lhs) const
235 if ( lhs.isNull() )
236 return lhs;
238 double nLhs = lhs;
239 return nLhs*fPi*(1.0/180.0);
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */