1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FNumericFunctions.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
35 #include "file/FNumericFunctions.hxx"
36 #include <rtl/math.hxx>
38 using namespace connectivity
;
39 using namespace connectivity::file
;
40 //------------------------------------------------------------------
41 ORowSetValue
OOp_Abs::operate(const ORowSetValue
& lhs
) const
51 //------------------------------------------------------------------
52 ORowSetValue
OOp_Sign::operate(const ORowSetValue
& lhs
) const
66 //------------------------------------------------------------------
67 ORowSetValue
OOp_Mod::operate(const ORowSetValue
& lhs
,const ORowSetValue
& rhs
) const
69 if ( lhs
.isNull() || rhs
.isNull() )
70 return ORowSetValue();
72 return fmod((double)lhs
,(double)rhs
);
74 //------------------------------------------------------------------
75 ORowSetValue
OOp_Floor::operate(const ORowSetValue
& lhs
) const
80 return floor((double)lhs
);
82 // -----------------------------------------------------------------------------
83 ORowSetValue
OOp_Ceiling::operate(const ORowSetValue
& lhs
) const
91 // -----------------------------------------------------------------------------
92 ORowSetValue
OOp_Round::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
94 if ( lhs
.empty() || lhs
.size() > 2 )
95 return ORowSetValue();
97 size_t nSize
= lhs
.size();
98 double nVal
= lhs
[nSize
-1];
101 if ( nSize
== 2 && !lhs
[0].isNull() )
103 return ::rtl::math::round(nVal
,nDec
);
105 // -----------------------------------------------------------------------------
106 ORowSetValue
OOp_Exp::operate(const ORowSetValue
& lhs
) const
114 // -----------------------------------------------------------------------------
115 ORowSetValue
OOp_Ln::operate(const ORowSetValue
& lhs
) const
117 if ( lhs
.isNull() || static_cast<double>(lhs
) < 0.0 )
122 if ( rtl::math::isNan(nVal
) )
123 return ORowSetValue();
126 // -----------------------------------------------------------------------------
127 ORowSetValue
OOp_Log::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
129 if ( lhs
.empty() || lhs
.size() > 2 )
130 return ORowSetValue();
131 size_t nSize
= lhs
.size();
132 double nVal
= log( (double)lhs
[nSize
-1] );
135 if ( nSize
== 2 && !lhs
[0].isNull() )
136 nVal
/= log((double)lhs
[0]);
138 if ( rtl::math::isNan(nVal
) )
139 return ORowSetValue();
142 // -----------------------------------------------------------------------------
143 ORowSetValue
OOp_Log10::operate(const ORowSetValue
& lhs
) const
145 if ( lhs
.isNull() || static_cast<double>(lhs
) < 0.0 )
148 double nVal
= log((double)lhs
);
149 if ( rtl::math::isNan(nVal
) )
150 return ORowSetValue();
154 // -----------------------------------------------------------------------------
155 ORowSetValue
OOp_Pow::operate(const ORowSetValue
& lhs
,const ORowSetValue
& rhs
) const
157 if ( lhs
.isNull() || rhs
.isNull() )
160 return pow((double)lhs
,(double)rhs
);
162 //------------------------------------------------------------------
163 ORowSetValue
OOp_Sqrt::operate(const ORowSetValue
& lhs
) const
168 double nVal
= sqrt((double)lhs
);
169 if ( rtl::math::isNan(nVal
) )
170 return ORowSetValue();
173 // -----------------------------------------------------------------------------
174 ORowSetValue
OOp_Pi::operate(const ::std::vector
<ORowSetValue
>& /*lhs*/) const
176 return 3.141592653589793116;
178 // -----------------------------------------------------------------------------
179 ORowSetValue
OOp_Cos::operate(const ORowSetValue
& lhs
) const
184 return cos((double)lhs
);
186 // -----------------------------------------------------------------------------
187 ORowSetValue
OOp_Sin::operate(const ORowSetValue
& lhs
) const
192 return sin((double)lhs
);
194 // -----------------------------------------------------------------------------
195 ORowSetValue
OOp_Tan::operate(const ORowSetValue
& lhs
) const
200 return tan((double)lhs
);
202 // -----------------------------------------------------------------------------
203 ORowSetValue
OOp_ACos::operate(const ORowSetValue
& lhs
) const
208 return acos((double)lhs
);
210 // -----------------------------------------------------------------------------
211 ORowSetValue
OOp_ASin::operate(const ORowSetValue
& lhs
) const
216 return asin((double)lhs
);
218 // -----------------------------------------------------------------------------
219 ORowSetValue
OOp_ATan::operate(const ORowSetValue
& lhs
) const
224 return atan((double)lhs
);
226 // -----------------------------------------------------------------------------
227 ORowSetValue
OOp_ATan2::operate(const ORowSetValue
& lhs
,const ORowSetValue
& rhs
) const
229 if ( lhs
.isNull() || rhs
.isNull() )
232 return atan2((double)lhs
,(double)rhs
);
234 // -----------------------------------------------------------------------------
235 ORowSetValue
OOp_Degrees::operate(const ORowSetValue
& lhs
) const
241 return nLhs
*180*(1.0/3.141592653589793116);
243 // -----------------------------------------------------------------------------
244 ORowSetValue
OOp_Radians::operate(const ORowSetValue
& lhs
) const
250 return nLhs
*3.141592653589793116*(1.0/180.0);
252 // -----------------------------------------------------------------------------