1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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
41 ORowSetValue
OOp_Sign::operate(const ORowSetValue
& lhs
) const
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
69 return floor(static_cast<double>(lhs
));
72 ORowSetValue
OOp_Ceiling::operate(const ORowSetValue
& lhs
) const
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];
90 if ( nSize
== 2 && !lhs
[0].isNull() )
92 return ::rtl::math::round(nVal
,nDec
);
95 ORowSetValue
OOp_Exp::operate(const ORowSetValue
& lhs
) const
104 ORowSetValue
OOp_Ln::operate(const ORowSetValue
& lhs
) const
106 if ( lhs
.isNull() || static_cast<double>(lhs
) < 0.0 )
111 if ( std::isnan(nVal
) )
112 return ORowSetValue();
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();
132 ORowSetValue
OOp_Log10::operate(const ORowSetValue
& lhs
) const
134 if ( lhs
.isNull() || static_cast<double>(lhs
) < 0.0 )
137 double nVal
= log(static_cast<double>(lhs
));
138 if ( std::isnan(nVal
) )
139 return ORowSetValue();
144 ORowSetValue
OOp_Pow::operate(const ORowSetValue
& lhs
,const ORowSetValue
& rhs
) const
146 if ( lhs
.isNull() || rhs
.isNull() )
149 return pow(static_cast<double>(lhs
),static_cast<double>(rhs
));
152 ORowSetValue
OOp_Sqrt::operate(const ORowSetValue
& lhs
) const
157 double nVal
= sqrt(static_cast<double>(lhs
));
158 if ( std::isnan(nVal
) )
159 return ORowSetValue();
163 ORowSetValue
OOp_Pi::operate(const std::vector
<ORowSetValue
>& /*lhs*/) const
168 ORowSetValue
OOp_Cos::operate(const ORowSetValue
& lhs
) const
173 return cos(static_cast<double>(lhs
));
176 ORowSetValue
OOp_Sin::operate(const ORowSetValue
& lhs
) const
181 return sin(static_cast<double>(lhs
));
184 ORowSetValue
OOp_Tan::operate(const ORowSetValue
& lhs
) const
189 return tan(static_cast<double>(lhs
));
192 ORowSetValue
OOp_ACos::operate(const ORowSetValue
& lhs
) const
197 return acos(static_cast<double>(lhs
));
200 ORowSetValue
OOp_ASin::operate(const ORowSetValue
& lhs
) const
205 return asin(static_cast<double>(lhs
));
208 ORowSetValue
OOp_ATan::operate(const ORowSetValue
& lhs
) const
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() )
221 return atan2(static_cast<double>(lhs
),static_cast<double>(rhs
));
224 ORowSetValue
OOp_Degrees::operate(const ORowSetValue
& lhs
) const
230 return nLhs
*180*(1.0/fPi
);
233 ORowSetValue
OOp_Radians::operate(const ORowSetValue
& lhs
) const
239 return nLhs
*fPi
*(1.0/180.0);
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */