LibreOffice Module connectivity (master) 1
FNumericFunctions.cxx
Go to the documentation of this file.
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>
24#include <rtl/math.hxx>
25
26using namespace connectivity;
27using namespace connectivity::file;
28
29ORowSetValue OOp_Abs::operate(const ORowSetValue& lhs) const
30{
31 if ( lhs.isNull() )
32 return lhs;
33
34 double nVal = lhs.getDouble();
35 if ( nVal < 0 )
36 nVal *= -1.0;
37 return fabs(nVal);
38}
39
41{
42 if ( lhs.isNull() )
43 return lhs;
44
45 sal_Int32 nRet = 0;
46 double nVal = lhs.getDouble();
47 if ( nVal < 0 )
48 nRet = -1;
49 else if ( nVal > 0 )
50 nRet = 1;
51
52 return nRet;
53}
54
56{
57 if ( lhs.isNull() || rhs.isNull() )
58 return ORowSetValue();
59
60 return fmod(lhs.getDouble(), rhs.getDouble());
61}
62
64{
65 if ( lhs.isNull() )
66 return lhs;
67
68 return floor(lhs.getDouble());
69}
70
72{
73 if ( lhs.isNull() )
74 return lhs;
75
76 double nVal = lhs.getDouble();
77 return ceil(nVal);
78}
79
80ORowSetValue OOp_Round::operate(const std::vector<ORowSetValue>& lhs) const
81{
82 if ( lhs.empty() || lhs.size() > 2 )
83 return ORowSetValue();
84
85 size_t nSize = lhs.size();
86 double nVal = lhs[nSize-1].getDouble();
87
88 sal_Int32 nDec = 0;
89 if ( nSize == 2 && !lhs[0].isNull() )
90 nDec = lhs[0].getDouble();
91 return ::rtl::math::round(nVal,nDec);
92}
93
95{
96 if ( lhs.isNull() )
97 return lhs;
98
99 double nVal = lhs.getDouble();
100 return exp(nVal);
101}
102
104{
105 if ( lhs.isNull() || lhs.getDouble() < 0.0 )
106 return lhs;
107
108 double nVal = lhs.getDouble();
109 nVal = log(nVal);
110 if ( std::isnan(nVal) )
111 return ORowSetValue();
112 return nVal;
113}
114
115ORowSetValue OOp_Log::operate(const std::vector<ORowSetValue>& lhs) const
116{
117 if ( lhs.empty() || lhs.size() > 2 )
118 return ORowSetValue();
119 size_t nSize = lhs.size();
120 double nVal = log( lhs[nSize-1].getDouble() );
121
122
123 if ( nSize == 2 && !lhs[0].isNull() )
124 nVal /= log(lhs[0].getDouble());
125
126 if ( std::isnan(nVal) )
127 return ORowSetValue();
128 return nVal;
129}
130
132{
133 if ( lhs.isNull() || lhs.getDouble() < 0.0 )
134 return lhs;
135
136 double nVal = log(lhs.getDouble());
137 if ( std::isnan(nVal) )
138 return ORowSetValue();
139 nVal /= log(10.0);
140 return nVal;
141}
142
144{
145 if ( lhs.isNull() || rhs.isNull() )
146 return lhs;
147
148 return pow(lhs.getDouble(), rhs.getDouble());
149}
150
152{
153 if ( lhs.isNull() )
154 return lhs;
155
156 double nVal = sqrt(lhs.getDouble());
157 if ( std::isnan(nVal) )
158 return ORowSetValue();
159 return nVal;
160}
161
162ORowSetValue OOp_Pi::operate(const std::vector<ORowSetValue>& /*lhs*/) const
163{
164 return M_PI;
165}
166
168{
169 if ( lhs.isNull() )
170 return lhs;
171
172 return cos(lhs.getDouble());
173}
174
176{
177 if ( lhs.isNull() )
178 return lhs;
179
180 return sin(lhs.getDouble());
181}
182
184{
185 if ( lhs.isNull() )
186 return lhs;
187
188 return tan(lhs.getDouble());
189}
190
192{
193 if ( lhs.isNull() )
194 return lhs;
195
196 return acos(lhs.getDouble());
197}
198
200{
201 if ( lhs.isNull() )
202 return lhs;
203
204 return asin(lhs.getDouble());
205}
206
208{
209 if ( lhs.isNull() )
210 return lhs;
211
212 return atan(lhs.getDouble());
213}
214
216{
217 if ( lhs.isNull() || rhs.isNull() )
218 return lhs;
219
220 return atan2(lhs.getDouble(), rhs.getDouble());
221}
222
224{
225 if ( lhs.isNull() )
226 return lhs;
227
228 double nLhs = lhs.getDouble();
229 return basegfx::rad2deg(nLhs);
230}
231
233{
234 if ( lhs.isNull() )
235 return lhs;
236
237 double nLhs = lhs.getDouble();
238 return basegfx::deg2rad(nLhs);
239}
240
241
242/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double getDouble() const
Definition: FValue.cxx:1745
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs, const ORowSetValue &rhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const std::vector< ORowSetValue > &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs, const ORowSetValue &rhs) const override
virtual ORowSetValue operate(const std::vector< ORowSetValue > &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs, const ORowSetValue &rhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const std::vector< ORowSetValue > &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
constexpr double rad2deg(double v)
constexpr double deg2rad(double v)
double getDouble(const Any &_rAny)
log