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 ORowSetValue
OOp_Abs::operate(const ORowSetValue
& lhs
) const
39 ORowSetValue
OOp_Sign::operate(const ORowSetValue
& lhs
) const
54 ORowSetValue
OOp_Mod::operate(const ORowSetValue
& lhs
,const ORowSetValue
& rhs
) const
56 if ( lhs
.isNull() || rhs
.isNull() )
57 return ORowSetValue();
59 return fmod((double)lhs
,(double)rhs
);
62 ORowSetValue
OOp_Floor::operate(const ORowSetValue
& lhs
) const
67 return floor((double)lhs
);
70 ORowSetValue
OOp_Ceiling::operate(const ORowSetValue
& lhs
) const
79 ORowSetValue
OOp_Round::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
81 if ( lhs
.empty() || lhs
.size() > 2 )
82 return ORowSetValue();
84 size_t nSize
= lhs
.size();
85 double nVal
= lhs
[nSize
-1];
88 if ( nSize
== 2 && !lhs
[0].isNull() )
90 return ::rtl::math::round(nVal
,nDec
);
93 ORowSetValue
OOp_Exp::operate(const ORowSetValue
& lhs
) const
102 ORowSetValue
OOp_Ln::operate(const ORowSetValue
& lhs
) const
104 if ( lhs
.isNull() || static_cast<double>(lhs
) < 0.0 )
109 if ( rtl::math::isNan(nVal
) )
110 return ORowSetValue();
114 ORowSetValue
OOp_Log::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
116 if ( lhs
.empty() || lhs
.size() > 2 )
117 return ORowSetValue();
118 size_t nSize
= lhs
.size();
119 double nVal
= log( (double)lhs
[nSize
-1] );
122 if ( nSize
== 2 && !lhs
[0].isNull() )
123 nVal
/= log((double)lhs
[0]);
125 if ( rtl::math::isNan(nVal
) )
126 return ORowSetValue();
130 ORowSetValue
OOp_Log10::operate(const ORowSetValue
& lhs
) const
132 if ( lhs
.isNull() || static_cast<double>(lhs
) < 0.0 )
135 double nVal
= log((double)lhs
);
136 if ( rtl::math::isNan(nVal
) )
137 return ORowSetValue();
142 ORowSetValue
OOp_Pow::operate(const ORowSetValue
& lhs
,const ORowSetValue
& rhs
) const
144 if ( lhs
.isNull() || rhs
.isNull() )
147 return pow((double)lhs
,(double)rhs
);
150 ORowSetValue
OOp_Sqrt::operate(const ORowSetValue
& lhs
) const
155 double nVal
= sqrt((double)lhs
);
156 if ( rtl::math::isNan(nVal
) )
157 return ORowSetValue();
161 ORowSetValue
OOp_Pi::operate(const ::std::vector
<ORowSetValue
>& /*lhs*/) const
163 return 3.141592653589793116;
166 ORowSetValue
OOp_Cos::operate(const ORowSetValue
& lhs
) const
171 return cos((double)lhs
);
174 ORowSetValue
OOp_Sin::operate(const ORowSetValue
& lhs
) const
179 return sin((double)lhs
);
182 ORowSetValue
OOp_Tan::operate(const ORowSetValue
& lhs
) const
187 return tan((double)lhs
);
190 ORowSetValue
OOp_ACos::operate(const ORowSetValue
& lhs
) const
195 return acos((double)lhs
);
198 ORowSetValue
OOp_ASin::operate(const ORowSetValue
& lhs
) const
203 return asin((double)lhs
);
206 ORowSetValue
OOp_ATan::operate(const ORowSetValue
& lhs
) const
211 return atan((double)lhs
);
214 ORowSetValue
OOp_ATan2::operate(const ORowSetValue
& lhs
,const ORowSetValue
& rhs
) const
216 if ( lhs
.isNull() || rhs
.isNull() )
219 return atan2((double)lhs
,(double)rhs
);
222 ORowSetValue
OOp_Degrees::operate(const ORowSetValue
& lhs
) const
228 return nLhs
*180*(1.0/3.141592653589793116);
231 ORowSetValue
OOp_Radians::operate(const ORowSetValue
& lhs
) const
237 return nLhs
*3.141592653589793116*(1.0/180.0);
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */