xref: /trunk/main/scaddins/source/analysis/analysis.cxx (revision a06b8d1bb8b9b0ee563e48b193d11bd9a9198b56)
1*a06b8d1bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*a06b8d1bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*a06b8d1bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*a06b8d1bSAndrew Rist  * distributed with this work for additional information
6*a06b8d1bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*a06b8d1bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*a06b8d1bSAndrew Rist  * "License"); you may not use this file except in compliance
9*a06b8d1bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*a06b8d1bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*a06b8d1bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*a06b8d1bSAndrew Rist  * software distributed under the License is distributed on an
15*a06b8d1bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a06b8d1bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*a06b8d1bSAndrew Rist  * specific language governing permissions and limitations
18*a06b8d1bSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*a06b8d1bSAndrew Rist  *************************************************************/
21*a06b8d1bSAndrew Rist 
22*a06b8d1bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "analysis.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
27cdf0e10cSrcweir #include <osl/diagnose.h>
28cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
29cdf0e10cSrcweir #include <rtl/math.hxx>
30cdf0e10cSrcweir #include <string.h>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <tools/resmgr.hxx>
33cdf0e10cSrcweir #include <tools/rcid.h>
34cdf0e10cSrcweir #include "analysis.hrc"
35cdf0e10cSrcweir #include "bessel.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #define ADDIN_SERVICE               "com.sun.star.sheet.AddIn"
38cdf0e10cSrcweir #define MY_SERVICE                  "com.sun.star.sheet.addin.Analysis"
39cdf0e10cSrcweir #define MY_IMPLNAME                 "com.sun.star.sheet.addin.AnalysisImpl"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using namespace                 ::rtl;
42cdf0e10cSrcweir using namespace                 ::com::sun::star;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //------------------------------------------------------------------
45cdf0e10cSrcweir //
46cdf0e10cSrcweir //  entry points for service registration / instantiation
47cdf0e10cSrcweir //
48cdf0e10cSrcweir //------------------------------------------------------------------
49cdf0e10cSrcweir 
50cdf0e10cSrcweir extern "C" {
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
53cdf0e10cSrcweir void SAL_CALL component_getImplementationEnvironment( const sal_Char** ppEnvTypeName, uno_Environment** /*ppEnv*/ )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir void* SAL_CALL component_getFactory( const sal_Char* pImplName, void* pServiceManager, void* /*pRegistryKey*/ )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     void*                                   pRet = 0;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     if( pServiceManager && STRING::createFromAscii( pImplName ) == AnalysisAddIn::getImplementationName_Static() )
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir         REF( lang::XSingleServiceFactory )  xFactory( cppu::createOneInstanceFactory(
65cdf0e10cSrcweir                 reinterpret_cast< lang::XMultiServiceFactory* >( pServiceManager ),
66cdf0e10cSrcweir                 AnalysisAddIn::getImplementationName_Static(),
67cdf0e10cSrcweir                 AnalysisAddIn_CreateInstance,
68cdf0e10cSrcweir                 AnalysisAddIn::getSupportedServiceNames_Static() ) );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         if( xFactory.is() )
71cdf0e10cSrcweir         {
72cdf0e10cSrcweir             xFactory->acquire();
73cdf0e10cSrcweir             pRet = xFactory.get();
74cdf0e10cSrcweir         }
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     return pRet;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir }   // extern C
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
86cdf0e10cSrcweir //------------------------------------------------------------------------
87cdf0e10cSrcweir //
88cdf0e10cSrcweir //  "normal" service implementation
89cdf0e10cSrcweir //
90cdf0e10cSrcweir //------------------------------------------------------------------------
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 
93cdf0e10cSrcweir ResMgr& AnalysisAddIn::GetResMgr( void ) THROWDEF_RTE
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     if( !pResMgr )
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         InitData();     // try to get resource manager
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         if( !pResMgr )
100cdf0e10cSrcweir             THROW_RTE;
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     return *pResMgr;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 
107cdf0e10cSrcweir STRING AnalysisAddIn::GetDisplFuncStr( sal_uInt16 nFuncNum ) THROWDEF_RTE
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     return String( AnalysisRscStrLoader( RID_ANALYSIS_FUNCTION_NAMES, nFuncNum, GetResMgr() ).GetString() );
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
113cdf0e10cSrcweir class AnalysisResourcePublisher : public Resource
114cdf0e10cSrcweir {
115cdf0e10cSrcweir public:
116cdf0e10cSrcweir                     AnalysisResourcePublisher( const AnalysisResId& rId ) : Resource( rId ) {}
117cdf0e10cSrcweir     sal_Bool            IsAvailableRes( const ResId& rId ) const { return Resource::IsAvailableRes( rId ); }
118cdf0e10cSrcweir     void            FreeResource() { Resource::FreeResource(); }
119cdf0e10cSrcweir };
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 
122cdf0e10cSrcweir class AnalysisFuncRes : public Resource
123cdf0e10cSrcweir {
124cdf0e10cSrcweir public:
125cdf0e10cSrcweir     AnalysisFuncRes( ResId& rRes, ResMgr& rResMgr, sal_uInt16 nInd, STRING& rRet );
126cdf0e10cSrcweir };
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
129cdf0e10cSrcweir AnalysisFuncRes::AnalysisFuncRes( ResId& rRes, ResMgr& rResMgr, sal_uInt16 nInd, STRING& rRet ) : Resource( rRes )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir     rRet = String( AnalysisResId( nInd, rResMgr ) );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     FreeResource();
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 
137cdf0e10cSrcweir STRING AnalysisAddIn::GetFuncDescrStr( sal_uInt16 nResId, sal_uInt16 nStrIndex ) THROWDEF_RTE
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     STRING                      aRet;
140cdf0e10cSrcweir     AnalysisResourcePublisher   aResPubl( AnalysisResId( RID_ANALYSIS_FUNCTION_DESCRIPTIONS, GetResMgr() ) );
141cdf0e10cSrcweir     AnalysisResId               aRes( nResId, GetResMgr() );
142cdf0e10cSrcweir     aRes.SetRT( RSC_RESOURCE );
143cdf0e10cSrcweir     if( aResPubl.IsAvailableRes( aRes ) )
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         AnalysisFuncRes         aSubRes( aRes, GetResMgr(), nStrIndex, aRet );
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     aResPubl.FreeResource();
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     return aRet;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 
154cdf0e10cSrcweir void AnalysisAddIn::InitData( void )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     if( pResMgr )
157cdf0e10cSrcweir         delete pResMgr;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     OString             aModName( "analysis" );
160cdf0e10cSrcweir     pResMgr = ResMgr::CreateResMgr( ( const sal_Char* ) aModName,
161cdf0e10cSrcweir                                         aFuncLoc );
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     if( pFD )
164cdf0e10cSrcweir         delete pFD;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     if( pResMgr )
167cdf0e10cSrcweir         pFD = new FuncDataList( *pResMgr );
168cdf0e10cSrcweir     else
169cdf0e10cSrcweir         pFD = NULL;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     if( pDefLocales )
172cdf0e10cSrcweir     {
173cdf0e10cSrcweir         delete pDefLocales;
174cdf0e10cSrcweir         pDefLocales = NULL;
175cdf0e10cSrcweir     }
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 
179cdf0e10cSrcweir AnalysisAddIn::AnalysisAddIn( const uno::Reference< lang::XMultiServiceFactory >& xServiceFact ) :
180cdf0e10cSrcweir     pDefLocales( NULL ),
181cdf0e10cSrcweir     pFD( NULL ),
182cdf0e10cSrcweir     pFactDoubles( NULL ),
183cdf0e10cSrcweir     pCDL( NULL ),
184cdf0e10cSrcweir     pResMgr( NULL ),
185cdf0e10cSrcweir     aAnyConv( xServiceFact )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
190cdf0e10cSrcweir AnalysisAddIn::~AnalysisAddIn()
191cdf0e10cSrcweir {
192cdf0e10cSrcweir     if( pFD )
193cdf0e10cSrcweir         delete pFD;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     if( pFactDoubles )
196cdf0e10cSrcweir         delete[] pFactDoubles;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     if( pCDL )
199cdf0e10cSrcweir         delete pCDL;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir //  if( pResMgr )           no delete, because _all_ resource managers are deleted _before_ this dtor is called
202cdf0e10cSrcweir //      delete pResMgr;
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     if( pDefLocales )
205cdf0e10cSrcweir         delete[] pDefLocales;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 
209cdf0e10cSrcweir sal_Int32 AnalysisAddIn::getDateMode(
210cdf0e10cSrcweir         const uno::Reference< beans::XPropertySet >& xPropSet,
211cdf0e10cSrcweir         const uno::Any& rAny ) throw( uno::RuntimeException, lang::IllegalArgumentException )
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     sal_Int32 nMode = aAnyConv.getInt32( xPropSet, rAny, 0 );
214cdf0e10cSrcweir     if( (nMode < 0) || (nMode > 4) )
215cdf0e10cSrcweir         throw lang::IllegalArgumentException();
216cdf0e10cSrcweir     return nMode;
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 
221cdf0e10cSrcweir //-----------------------------------------------------------------------------
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 
224cdf0e10cSrcweir #define MAXFACTDOUBLE   300
225cdf0e10cSrcweir 
226cdf0e10cSrcweir double AnalysisAddIn::FactDouble( sal_Int32 nNum ) THROWDEF_RTE_IAE
227cdf0e10cSrcweir {
228cdf0e10cSrcweir     if( nNum < 0 || nNum > MAXFACTDOUBLE )
229cdf0e10cSrcweir         THROW_IAE;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     if( !pFactDoubles )
232cdf0e10cSrcweir     {
233cdf0e10cSrcweir         pFactDoubles = new double[ MAXFACTDOUBLE + 1 ];
234cdf0e10cSrcweir 
235cdf0e10cSrcweir         pFactDoubles[ 0 ] = 1.0;    // by default
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         double      fOdd = 1.0;
238cdf0e10cSrcweir         double      fEven = 2.0;
239cdf0e10cSrcweir 
240cdf0e10cSrcweir         pFactDoubles[ 1 ] = fOdd;
241cdf0e10cSrcweir         pFactDoubles[ 2 ] = fEven;
242cdf0e10cSrcweir 
243cdf0e10cSrcweir         sal_Bool    bOdd = sal_True;
244cdf0e10cSrcweir 
245cdf0e10cSrcweir         for( sal_uInt16 nCnt = 3 ; nCnt <= MAXFACTDOUBLE ; nCnt++ )
246cdf0e10cSrcweir         {
247cdf0e10cSrcweir             if( bOdd )
248cdf0e10cSrcweir             {
249cdf0e10cSrcweir                 fOdd *= nCnt;
250cdf0e10cSrcweir                 pFactDoubles[ nCnt ] = fOdd;
251cdf0e10cSrcweir             }
252cdf0e10cSrcweir             else
253cdf0e10cSrcweir             {
254cdf0e10cSrcweir                 fEven *= nCnt;
255cdf0e10cSrcweir                 pFactDoubles[ nCnt ] = fEven;
256cdf0e10cSrcweir             }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir             bOdd = !bOdd;
259cdf0e10cSrcweir 
260cdf0e10cSrcweir         }
261cdf0e10cSrcweir     }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir     return pFactDoubles[ nNum ];
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 
267cdf0e10cSrcweir STRING AnalysisAddIn::getImplementationName_Static()
268cdf0e10cSrcweir {
269cdf0e10cSrcweir     return STRFROMASCII( MY_IMPLNAME );
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 
273cdf0e10cSrcweir SEQ( STRING ) AnalysisAddIn::getSupportedServiceNames_Static()
274cdf0e10cSrcweir {
275cdf0e10cSrcweir     SEQ( STRING )   aRet(2);
276cdf0e10cSrcweir     STRING*         pArray = aRet.getArray();
277cdf0e10cSrcweir     pArray[0] = STRFROMASCII( ADDIN_SERVICE );
278cdf0e10cSrcweir     pArray[1] = STRFROMASCII( MY_SERVICE );
279cdf0e10cSrcweir     return aRet;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 
283cdf0e10cSrcweir REF( uno::XInterface ) SAL_CALL AnalysisAddIn_CreateInstance(
284cdf0e10cSrcweir         const uno::Reference< lang::XMultiServiceFactory >& xServiceFact )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir     static uno::Reference< uno::XInterface > xInst = (cppu::OWeakObject*) new AnalysisAddIn( xServiceFact );
287cdf0e10cSrcweir     return xInst;
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 
291cdf0e10cSrcweir // XServiceName
292cdf0e10cSrcweir 
293cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getServiceName() THROWDEF_RTE
294cdf0e10cSrcweir {
295cdf0e10cSrcweir     // name of specific AddIn service
296cdf0e10cSrcweir     return STRFROMASCII( MY_SERVICE );
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 
300cdf0e10cSrcweir // XServiceInfo
301cdf0e10cSrcweir 
302cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImplementationName() THROWDEF_RTE
303cdf0e10cSrcweir {
304cdf0e10cSrcweir     return getImplementationName_Static();
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir 
308cdf0e10cSrcweir sal_Bool SAL_CALL AnalysisAddIn::supportsService( const STRING& aName ) THROWDEF_RTE
309cdf0e10cSrcweir {
310cdf0e10cSrcweir     return aName.compareToAscii( ADDIN_SERVICE ) == 0 || aName.compareToAscii( MY_SERVICE ) == 0;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 
314cdf0e10cSrcweir SEQ( STRING ) SAL_CALL AnalysisAddIn::getSupportedServiceNames() THROWDEF_RTE
315cdf0e10cSrcweir {
316cdf0e10cSrcweir     return getSupportedServiceNames_Static();
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 
320cdf0e10cSrcweir // XLocalizable
321cdf0e10cSrcweir 
322cdf0e10cSrcweir void SAL_CALL AnalysisAddIn::setLocale( const lang::Locale& eLocale ) THROWDEF_RTE
323cdf0e10cSrcweir {
324cdf0e10cSrcweir     aFuncLoc = eLocale;
325cdf0e10cSrcweir 
326cdf0e10cSrcweir     InitData();     // change of locale invalidates resources!
327cdf0e10cSrcweir }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir lang::Locale SAL_CALL AnalysisAddIn::getLocale() THROWDEF_RTE
330cdf0e10cSrcweir {
331cdf0e10cSrcweir     return aFuncLoc;
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 
335cdf0e10cSrcweir // XAddIn
336cdf0e10cSrcweir 
337cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getProgrammaticFuntionName( const STRING& ) THROWDEF_RTE
338cdf0e10cSrcweir {
339cdf0e10cSrcweir     //  not used by calc
340cdf0e10cSrcweir     //  (but should be implemented for other uses of the AddIn service)
341cdf0e10cSrcweir 
342cdf0e10cSrcweir     return STRING();
343cdf0e10cSrcweir }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 
346cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getDisplayFunctionName( const STRING& aProgrammaticName ) THROWDEF_RTE
347cdf0e10cSrcweir {
348cdf0e10cSrcweir     STRING          aRet;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     const FuncData* p = pFD->Get( aProgrammaticName );
351cdf0e10cSrcweir     if( p )
352cdf0e10cSrcweir     {
353cdf0e10cSrcweir         aRet = GetDisplFuncStr( p->GetUINameID() );
354cdf0e10cSrcweir         if( p->IsDouble() )
355cdf0e10cSrcweir             aRet += STRFROMANSI( "_ADD" );
356cdf0e10cSrcweir     }
357cdf0e10cSrcweir     else
358cdf0e10cSrcweir     {
359cdf0e10cSrcweir         aRet = STRFROMANSI( "UNKNOWNFUNC_" );
360cdf0e10cSrcweir         aRet += aProgrammaticName;
361cdf0e10cSrcweir     }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir     return aRet;
364cdf0e10cSrcweir }
365cdf0e10cSrcweir 
366cdf0e10cSrcweir 
367cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getFunctionDescription( const STRING& aProgrammaticName ) THROWDEF_RTE
368cdf0e10cSrcweir {
369cdf0e10cSrcweir     STRING          aRet;
370cdf0e10cSrcweir 
371cdf0e10cSrcweir     const FuncData* p = pFD->Get( aProgrammaticName );
372cdf0e10cSrcweir     if( p )
373cdf0e10cSrcweir         aRet = GetFuncDescrStr( p->GetDescrID(), 1 );
374cdf0e10cSrcweir 
375cdf0e10cSrcweir     return aRet;
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir 
379cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getDisplayArgumentName( const STRING& aName, sal_Int32 nArg ) THROWDEF_RTE
380cdf0e10cSrcweir {
381cdf0e10cSrcweir     STRING          aRet;
382cdf0e10cSrcweir 
383cdf0e10cSrcweir     const FuncData* p = pFD->Get( aName );
384cdf0e10cSrcweir     if( p && nArg <= 0xFFFF )
385cdf0e10cSrcweir     {
386cdf0e10cSrcweir         sal_uInt16  nStr = p->GetStrIndex( sal_uInt16( nArg ) );
387cdf0e10cSrcweir         if( nStr /*&& nStr < 4*/ )
388cdf0e10cSrcweir             aRet = GetFuncDescrStr( p->GetDescrID(), nStr );
389cdf0e10cSrcweir         else
390cdf0e10cSrcweir             aRet = STRFROMANSI( "internal" );
391cdf0e10cSrcweir     }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir     return aRet;
394cdf0e10cSrcweir }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 
397cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getArgumentDescription( const STRING& aName, sal_Int32 nArg ) THROWDEF_RTE
398cdf0e10cSrcweir {
399cdf0e10cSrcweir     STRING          aRet;
400cdf0e10cSrcweir 
401cdf0e10cSrcweir     const FuncData* p = pFD->Get( aName );
402cdf0e10cSrcweir     if( p && nArg <= 0xFFFF )
403cdf0e10cSrcweir     {
404cdf0e10cSrcweir         sal_uInt16  nStr = p->GetStrIndex( sal_uInt16( nArg ) );
405cdf0e10cSrcweir         if( nStr /*&& nStr < 4*/ )
406cdf0e10cSrcweir             aRet = GetFuncDescrStr( p->GetDescrID(), nStr + 1 );
407cdf0e10cSrcweir         else
408cdf0e10cSrcweir             aRet = STRFROMANSI( "for internal use only" );
409cdf0e10cSrcweir     }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir     return aRet;
412cdf0e10cSrcweir }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 
415cdf0e10cSrcweir static const char*  pDefCatName = "Add-In";
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 
418cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getProgrammaticCategoryName( const STRING& aName ) THROWDEF_RTE
419cdf0e10cSrcweir {
420cdf0e10cSrcweir     //  return non-translated strings
421cdf0e10cSrcweir //  return STRFROMASCII( "Add-In" );
422cdf0e10cSrcweir     const FuncData*     p = pFD->Get( aName );
423cdf0e10cSrcweir     STRING              aRet;
424cdf0e10cSrcweir     if( p )
425cdf0e10cSrcweir     {
426cdf0e10cSrcweir         const sal_Char* pStr;
427cdf0e10cSrcweir 
428cdf0e10cSrcweir         switch( p->GetCategory() )
429cdf0e10cSrcweir         {
430cdf0e10cSrcweir             case FDCat_DateTime:    pStr = "Date&Time";         break;
431cdf0e10cSrcweir             case FDCat_Finance:     pStr = "Financial";         break;
432cdf0e10cSrcweir             case FDCat_Inf:         pStr = "Information";       break;
433cdf0e10cSrcweir             case FDCat_Math:        pStr = "Mathematical";      break;
434cdf0e10cSrcweir             case FDCat_Tech:        pStr = "Technical";         break;
435cdf0e10cSrcweir             default:
436cdf0e10cSrcweir                                     pStr = pDefCatName;         break;
437cdf0e10cSrcweir         }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir         aRet = STRFROMASCII( pStr );
440cdf0e10cSrcweir     }
441cdf0e10cSrcweir     else
442cdf0e10cSrcweir         aRet = STRFROMASCII( pDefCatName );
443cdf0e10cSrcweir 
444cdf0e10cSrcweir     return aRet;
445cdf0e10cSrcweir }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 
448cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getDisplayCategoryName( const STRING& aProgrammaticFunctionName ) THROWDEF_RTE
449cdf0e10cSrcweir {
450cdf0e10cSrcweir     //  return translated strings, not used for predefined categories
451cdf0e10cSrcweir //  return STRFROMASCII( "Add-In" );
452cdf0e10cSrcweir     const FuncData*     p = pFD->Get( aProgrammaticFunctionName );
453cdf0e10cSrcweir     STRING              aRet;
454cdf0e10cSrcweir     if( p )
455cdf0e10cSrcweir     {
456cdf0e10cSrcweir         const sal_Char* pStr;
457cdf0e10cSrcweir 
458cdf0e10cSrcweir         switch( p->GetCategory() )
459cdf0e10cSrcweir         {
460cdf0e10cSrcweir             case FDCat_DateTime:    pStr = "Date&Time";         break;
461cdf0e10cSrcweir             case FDCat_Finance:     pStr = "Financial";         break;
462cdf0e10cSrcweir             case FDCat_Inf:         pStr = "Information";       break;
463cdf0e10cSrcweir             case FDCat_Math:        pStr = "Mathematical";      break;
464cdf0e10cSrcweir             case FDCat_Tech:        pStr = "Technical";         break;
465cdf0e10cSrcweir             default:
466cdf0e10cSrcweir                                     pStr = pDefCatName;         break;
467cdf0e10cSrcweir         }
468cdf0e10cSrcweir 
469cdf0e10cSrcweir         aRet = STRFROMASCII( pStr );
470cdf0e10cSrcweir     }
471cdf0e10cSrcweir     else
472cdf0e10cSrcweir         aRet = STRFROMASCII( pDefCatName );
473cdf0e10cSrcweir 
474cdf0e10cSrcweir     return aRet;
475cdf0e10cSrcweir }
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 
478cdf0e10cSrcweir static const sal_Char*      pLang[] = { "de", "en" };
479cdf0e10cSrcweir static const sal_Char*      pCoun[] = { "DE", "US" };
480cdf0e10cSrcweir static const sal_uInt32     nNumOfLoc = sizeof( pLang ) / sizeof( sal_Char* );
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 
483cdf0e10cSrcweir void AnalysisAddIn::InitDefLocales( void )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir     pDefLocales = new CSS::lang::Locale[ nNumOfLoc ];
486cdf0e10cSrcweir 
487cdf0e10cSrcweir     for( sal_uInt32 n = 0 ; n < nNumOfLoc ; n++ )
488cdf0e10cSrcweir     {
489cdf0e10cSrcweir         pDefLocales[ n ].Language = STRING::createFromAscii( pLang[ n ] );
490cdf0e10cSrcweir         pDefLocales[ n ].Country = STRING::createFromAscii( pCoun[ n ] );
491cdf0e10cSrcweir     }
492cdf0e10cSrcweir }
493cdf0e10cSrcweir 
494cdf0e10cSrcweir 
495cdf0e10cSrcweir inline const CSS::lang::Locale& AnalysisAddIn::GetLocale( sal_uInt32 nInd )
496cdf0e10cSrcweir {
497cdf0e10cSrcweir     if( !pDefLocales )
498cdf0e10cSrcweir         InitDefLocales();
499cdf0e10cSrcweir 
500cdf0e10cSrcweir     if( nInd < sizeof( pLang ) )
501cdf0e10cSrcweir         return pDefLocales[ nInd ];
502cdf0e10cSrcweir     else
503cdf0e10cSrcweir         return aFuncLoc;
504cdf0e10cSrcweir }
505cdf0e10cSrcweir 
506cdf0e10cSrcweir 
507cdf0e10cSrcweir SEQofLocName SAL_CALL AnalysisAddIn::getCompatibilityNames( const STRING& aProgrammaticName ) THROWDEF_RTE
508cdf0e10cSrcweir {
509cdf0e10cSrcweir     const FuncData*             p = pFD->Get( aProgrammaticName );
510cdf0e10cSrcweir 
511cdf0e10cSrcweir     if( !p )
512cdf0e10cSrcweir         return SEQofLocName( 0 );
513cdf0e10cSrcweir 
514cdf0e10cSrcweir     const StringList&           r = p->GetCompNameList();
515cdf0e10cSrcweir     sal_uInt32                  nCount = r.Count();
516cdf0e10cSrcweir 
517cdf0e10cSrcweir     SEQofLocName                aRet( nCount );
518cdf0e10cSrcweir 
519cdf0e10cSrcweir     CSS::sheet::LocalizedName*  pArray = aRet.getArray();
520cdf0e10cSrcweir 
521cdf0e10cSrcweir     for( sal_uInt32 n = 0 ; n < nCount ; n++ )
522cdf0e10cSrcweir     {
523cdf0e10cSrcweir         pArray[ n ] = CSS::sheet::LocalizedName( GetLocale( n ), *r.Get( n ) );
524cdf0e10cSrcweir     }
525cdf0e10cSrcweir 
526cdf0e10cSrcweir     return aRet;
527cdf0e10cSrcweir }
528cdf0e10cSrcweir 
529cdf0e10cSrcweir 
530cdf0e10cSrcweir // XAnalysis
531cdf0e10cSrcweir 
532cdf0e10cSrcweir /*double SAL_CALL AnalysisAddIn::get_Test( constREFXPS&,
533cdf0e10cSrcweir     sal_Int32 nMode, double f1, double f2, double f3 ) THROWDEF_RTE
534cdf0e10cSrcweir {
535cdf0e10cSrcweir     return _Test( nMode, f1, f2, f3 );
536cdf0e10cSrcweir }*/
537cdf0e10cSrcweir 
538cdf0e10cSrcweir 
539cdf0e10cSrcweir /**
540cdf0e10cSrcweir  * Workday
541cdf0e10cSrcweir  */
542cdf0e10cSrcweir 
543cdf0e10cSrcweir sal_Int32 SAL_CALL AnalysisAddIn::getWorkday( constREFXPS& xOptions,
544cdf0e10cSrcweir     sal_Int32 nDate, sal_Int32 nDays, const ANY& aHDay ) THROWDEF_RTE_IAE
545cdf0e10cSrcweir {
546cdf0e10cSrcweir     if( !nDays )
547cdf0e10cSrcweir         return nDate;
548cdf0e10cSrcweir 
549cdf0e10cSrcweir     sal_Int32                   nNullDate = GetNullDate( xOptions );
550cdf0e10cSrcweir 
551cdf0e10cSrcweir     SortedIndividualInt32List   aSrtLst;
552cdf0e10cSrcweir 
553cdf0e10cSrcweir     aSrtLst.InsertHolidayList( aAnyConv, xOptions, aHDay, nNullDate, sal_False );
554cdf0e10cSrcweir 
555cdf0e10cSrcweir     sal_Int32                   nActDate = nDate + nNullDate;
556cdf0e10cSrcweir 
557cdf0e10cSrcweir     if( nDays > 0 )
558cdf0e10cSrcweir     {
559cdf0e10cSrcweir         if( GetDayOfWeek( nActDate ) == 5 )
560cdf0e10cSrcweir             // when starting on Saturday, assuming we're starting on Sunday to get the jump over the weekend
561cdf0e10cSrcweir             nActDate++;
562cdf0e10cSrcweir 
563cdf0e10cSrcweir         while( nDays )
564cdf0e10cSrcweir         {
565cdf0e10cSrcweir             nActDate++;
566cdf0e10cSrcweir 
567cdf0e10cSrcweir             if( GetDayOfWeek( nActDate ) < 5 )
568cdf0e10cSrcweir             {
569cdf0e10cSrcweir                 if( !aSrtLst.Find( nActDate ) )
570cdf0e10cSrcweir                     nDays--;
571cdf0e10cSrcweir             }
572cdf0e10cSrcweir             else
573cdf0e10cSrcweir                 nActDate++;     // jump over weekend
574cdf0e10cSrcweir         }
575cdf0e10cSrcweir     }
576cdf0e10cSrcweir     else
577cdf0e10cSrcweir     {
578cdf0e10cSrcweir         if( GetDayOfWeek( nActDate ) == 6 )
579cdf0e10cSrcweir             // when starting on Sunday, assuming we're starting on Saturday to get the jump over the weekend
580cdf0e10cSrcweir             nActDate--;
581cdf0e10cSrcweir 
582cdf0e10cSrcweir         while( nDays )
583cdf0e10cSrcweir         {
584cdf0e10cSrcweir             nActDate--;
585cdf0e10cSrcweir 
586cdf0e10cSrcweir             if( GetDayOfWeek( nActDate ) < 5 )
587cdf0e10cSrcweir             {
588cdf0e10cSrcweir                 if( !aSrtLst.Find( nActDate ) )
589cdf0e10cSrcweir                     nDays++;
590cdf0e10cSrcweir             }
591cdf0e10cSrcweir             else
592cdf0e10cSrcweir                 nActDate--;     // jump over weekend
593cdf0e10cSrcweir         }
594cdf0e10cSrcweir     }
595cdf0e10cSrcweir 
596cdf0e10cSrcweir     return nActDate - nNullDate;
597cdf0e10cSrcweir }
598cdf0e10cSrcweir 
599cdf0e10cSrcweir 
600cdf0e10cSrcweir /**
601cdf0e10cSrcweir  * Yearfrac
602cdf0e10cSrcweir  */
603cdf0e10cSrcweir 
604cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getYearfrac( constREFXPS& xOpt,
605cdf0e10cSrcweir     sal_Int32 nStartDate, sal_Int32 nEndDate, const ANY& rMode ) THROWDEF_RTE_IAE
606cdf0e10cSrcweir {
607cdf0e10cSrcweir     double fRet = GetYearFrac( xOpt, nStartDate, nEndDate, getDateMode( xOpt, rMode ) );
608cdf0e10cSrcweir     RETURN_FINITE( fRet );
609cdf0e10cSrcweir }
610cdf0e10cSrcweir 
611cdf0e10cSrcweir 
612cdf0e10cSrcweir sal_Int32 SAL_CALL AnalysisAddIn::getEdate( constREFXPS& xOpt, sal_Int32 nStartDate, sal_Int32 nMonths ) THROWDEF_RTE_IAE
613cdf0e10cSrcweir {
614cdf0e10cSrcweir     sal_Int32 nNullDate = GetNullDate( xOpt );
615cdf0e10cSrcweir     ScaDate aDate( nNullDate, nStartDate, 5 );
616cdf0e10cSrcweir     aDate.addMonths( nMonths );
617cdf0e10cSrcweir     return aDate.getDate( nNullDate );
618cdf0e10cSrcweir }
619cdf0e10cSrcweir 
620cdf0e10cSrcweir 
621cdf0e10cSrcweir sal_Int32 SAL_CALL AnalysisAddIn::getWeeknum( constREFXPS& xOpt, sal_Int32 nDate, sal_Int32 nMode ) THROWDEF_RTE_IAE
622cdf0e10cSrcweir {
623cdf0e10cSrcweir     nDate += GetNullDate( xOpt );
624cdf0e10cSrcweir 
625cdf0e10cSrcweir     sal_uInt16  nDay, nMonth, nYear;
626cdf0e10cSrcweir     DaysToDate( nDate, nDay, nMonth, nYear );
627cdf0e10cSrcweir 
628cdf0e10cSrcweir     sal_Int32   nFirstInYear = DateToDays( 1, 1, nYear );
629cdf0e10cSrcweir     sal_uInt16  nFirstDayInYear = GetDayOfWeek( nFirstInYear );
630cdf0e10cSrcweir 
631cdf0e10cSrcweir     return ( nDate - nFirstInYear + ( ( nMode == 1 )? ( nFirstDayInYear + 1 ) % 7 : nFirstDayInYear ) ) / 7 + 1;
632cdf0e10cSrcweir }
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 
635cdf0e10cSrcweir sal_Int32 SAL_CALL AnalysisAddIn::getEomonth( constREFXPS& xOpt, sal_Int32 nDate, sal_Int32 nMonths ) THROWDEF_RTE_IAE
636cdf0e10cSrcweir {
637cdf0e10cSrcweir     sal_Int32   nNullDate = GetNullDate( xOpt );
638cdf0e10cSrcweir     nDate += nNullDate;
639cdf0e10cSrcweir     sal_uInt16  nDay, nMonth, nYear;
640cdf0e10cSrcweir     DaysToDate( nDate, nDay, nMonth, nYear );
641cdf0e10cSrcweir 
642cdf0e10cSrcweir     sal_Int32   nNewMonth = nMonth + nMonths;
643cdf0e10cSrcweir 
644cdf0e10cSrcweir     if( nNewMonth > 12 )
645cdf0e10cSrcweir     {
646cdf0e10cSrcweir         nYear = sal::static_int_cast<sal_uInt16>( nYear + ( nNewMonth / 12 ) );
647cdf0e10cSrcweir         nNewMonth %= 12;
648cdf0e10cSrcweir     }
649cdf0e10cSrcweir     else if( nNewMonth < 1 )
650cdf0e10cSrcweir     {
651cdf0e10cSrcweir         nNewMonth = -nNewMonth;
652cdf0e10cSrcweir         nYear = sal::static_int_cast<sal_uInt16>( nYear - ( nNewMonth / 12 ) );
653cdf0e10cSrcweir         nYear--;
654cdf0e10cSrcweir         nNewMonth %= 12;
655cdf0e10cSrcweir         nNewMonth = 12 - nNewMonth;
656cdf0e10cSrcweir     }
657cdf0e10cSrcweir 
658cdf0e10cSrcweir     return DateToDays( DaysInMonth( sal_uInt16( nNewMonth ), nYear ), sal_uInt16( nNewMonth ), nYear ) - nNullDate;
659cdf0e10cSrcweir }
660cdf0e10cSrcweir 
661cdf0e10cSrcweir 
662cdf0e10cSrcweir sal_Int32 SAL_CALL AnalysisAddIn::getNetworkdays( constREFXPS& xOpt,
663cdf0e10cSrcweir         sal_Int32 nStartDate, sal_Int32 nEndDate, const ANY& aHDay ) THROWDEF_RTE_IAE
664cdf0e10cSrcweir {
665cdf0e10cSrcweir     sal_Int32                   nNullDate = GetNullDate( xOpt );
666cdf0e10cSrcweir 
667cdf0e10cSrcweir     SortedIndividualInt32List   aSrtLst;
668cdf0e10cSrcweir 
669cdf0e10cSrcweir     aSrtLst.InsertHolidayList( aAnyConv, xOpt, aHDay, nNullDate, sal_False );
670cdf0e10cSrcweir 
671cdf0e10cSrcweir     sal_Int32                   nActDate = nStartDate + nNullDate;
672cdf0e10cSrcweir     sal_Int32                   nStopDate = nEndDate + nNullDate;
673cdf0e10cSrcweir     sal_Int32                   nCnt = 0;
674cdf0e10cSrcweir 
675cdf0e10cSrcweir     if( nActDate <= nStopDate )
676cdf0e10cSrcweir     {
677cdf0e10cSrcweir         while( nActDate <= nStopDate )
678cdf0e10cSrcweir         {
679cdf0e10cSrcweir             if( GetDayOfWeek( nActDate ) < 5 && !aSrtLst.Find( nActDate ) )
680cdf0e10cSrcweir                 nCnt++;
681cdf0e10cSrcweir 
682cdf0e10cSrcweir             nActDate++;
683cdf0e10cSrcweir         }
684cdf0e10cSrcweir     }
685cdf0e10cSrcweir     else
686cdf0e10cSrcweir     {
687cdf0e10cSrcweir         while( nActDate >= nStopDate )
688cdf0e10cSrcweir         {
689cdf0e10cSrcweir             if( GetDayOfWeek( nActDate ) < 5 && !aSrtLst.Find( nActDate ) )
690cdf0e10cSrcweir                 nCnt--;
691cdf0e10cSrcweir 
692cdf0e10cSrcweir             nActDate--;
693cdf0e10cSrcweir         }
694cdf0e10cSrcweir     }
695cdf0e10cSrcweir 
696cdf0e10cSrcweir     return nCnt;
697cdf0e10cSrcweir }
698cdf0e10cSrcweir 
699cdf0e10cSrcweir 
700cdf0e10cSrcweir sal_Int32 SAL_CALL AnalysisAddIn::getIseven( sal_Int32 nVal ) THROWDEF_RTE_IAE
701cdf0e10cSrcweir {
702cdf0e10cSrcweir     return ( nVal & 0x00000001 )? 0 : 1;
703cdf0e10cSrcweir }
704cdf0e10cSrcweir 
705cdf0e10cSrcweir 
706cdf0e10cSrcweir sal_Int32 SAL_CALL AnalysisAddIn::getIsodd( sal_Int32 nVal ) THROWDEF_RTE_IAE
707cdf0e10cSrcweir {
708cdf0e10cSrcweir     return ( nVal & 0x00000001 )? 1 : 0;
709cdf0e10cSrcweir }
710cdf0e10cSrcweir 
711cdf0e10cSrcweir double SAL_CALL
712cdf0e10cSrcweir AnalysisAddIn::getMultinomial( constREFXPS& xOpt, const SEQSEQ( sal_Int32 )& aVLst,
713cdf0e10cSrcweir                                const SEQ( uno::Any )& aOptVLst ) THROWDEF_RTE_IAE
714cdf0e10cSrcweir {
715cdf0e10cSrcweir     ScaDoubleListGE0 aValList;
716cdf0e10cSrcweir 
717cdf0e10cSrcweir     aValList.Append( aVLst );
718cdf0e10cSrcweir     aValList.Append( aAnyConv, xOpt, aOptVLst );
719cdf0e10cSrcweir 
720cdf0e10cSrcweir     if( aValList.Count() == 0 )
721cdf0e10cSrcweir         return 0.0;
722cdf0e10cSrcweir 
723cdf0e10cSrcweir     sal_Int32 nZ = 0;
724cdf0e10cSrcweir     double    fN = 1.0;
725cdf0e10cSrcweir 
726cdf0e10cSrcweir     for( const double *p = aValList.First(); p; p = aValList.Next() )
727cdf0e10cSrcweir     {
728cdf0e10cSrcweir         double fInt = (*p >= 0.0) ? rtl::math::approxFloor( *p ) : rtl::math::approxCeil( *p );
729cdf0e10cSrcweir         if ( fInt < 0.0 || fInt > 170.0 )
730cdf0e10cSrcweir             THROW_IAE;
731cdf0e10cSrcweir         sal_Int32 n = static_cast< sal_Int32 >( fInt );
732cdf0e10cSrcweir         if( n > 0 )
733cdf0e10cSrcweir         {
734cdf0e10cSrcweir             nZ += n;
735cdf0e10cSrcweir             fN *= Fak( n );
736cdf0e10cSrcweir         }
737cdf0e10cSrcweir     }
738cdf0e10cSrcweir 
739cdf0e10cSrcweir     if( nZ > 170 )
740cdf0e10cSrcweir         THROW_IAE;
741cdf0e10cSrcweir 
742cdf0e10cSrcweir     double fRet = Fak( nZ ) / fN;
743cdf0e10cSrcweir     RETURN_FINITE( fRet );
744cdf0e10cSrcweir }
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 
747cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getSeriessum( double fX, double fN, double fM, const SEQSEQ( double )& aCoeffList ) THROWDEF_RTE_IAE
748cdf0e10cSrcweir {
749cdf0e10cSrcweir     double                          fRet = 0.0;
750cdf0e10cSrcweir 
751cdf0e10cSrcweir     // #i32269# 0^0 is undefined, Excel returns #NUM! error
752cdf0e10cSrcweir     if( fX == 0.0 && fN == 0 )
753cdf0e10cSrcweir         THROW_RTE;
754cdf0e10cSrcweir 
755cdf0e10cSrcweir     if( fX != 0.0 )
756cdf0e10cSrcweir     {
757cdf0e10cSrcweir         sal_Int32       n1, n2;
758cdf0e10cSrcweir         sal_Int32       nE1 = aCoeffList.getLength();
759cdf0e10cSrcweir         sal_Int32       nE2;
760cdf0e10cSrcweir         //sal_Int32     nZ = 0;
761cdf0e10cSrcweir 
762cdf0e10cSrcweir         for( n1 = 0 ; n1 < nE1 ; n1++ )
763cdf0e10cSrcweir         {
764cdf0e10cSrcweir             const SEQ( double )&    rList = aCoeffList[ n1 ];
765cdf0e10cSrcweir             nE2 = rList.getLength();
766cdf0e10cSrcweir             const double*           pList = rList.getConstArray();
767cdf0e10cSrcweir 
768cdf0e10cSrcweir             for( n2 = 0 ; n2 < nE2 ; n2++ )
769cdf0e10cSrcweir             {
770cdf0e10cSrcweir                 fRet += pList[ n2 ] * pow( fX, fN );
771cdf0e10cSrcweir 
772cdf0e10cSrcweir                 fN += fM;
773cdf0e10cSrcweir             }
774cdf0e10cSrcweir         }
775cdf0e10cSrcweir     }
776cdf0e10cSrcweir 
777cdf0e10cSrcweir     RETURN_FINITE( fRet );
778cdf0e10cSrcweir }
779cdf0e10cSrcweir 
780cdf0e10cSrcweir 
781cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getQuotient( double fNum, double fDenom ) THROWDEF_RTE_IAE
782cdf0e10cSrcweir {
783cdf0e10cSrcweir     double fRet;
784cdf0e10cSrcweir     if( (fNum < 0) != (fDenom < 0) )
785cdf0e10cSrcweir         fRet = ::rtl::math::approxCeil( fNum / fDenom );
786cdf0e10cSrcweir     else
787cdf0e10cSrcweir         fRet = ::rtl::math::approxFloor( fNum / fDenom );
788cdf0e10cSrcweir     RETURN_FINITE( fRet );
789cdf0e10cSrcweir }
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 
792cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getMround( double fNum, double fMult ) THROWDEF_RTE_IAE
793cdf0e10cSrcweir {
794cdf0e10cSrcweir     if( fMult == 0.0 )
795cdf0e10cSrcweir         return fMult;
796cdf0e10cSrcweir 
797cdf0e10cSrcweir     double fRet = fMult * ::rtl::math::round( fNum / fMult );
798cdf0e10cSrcweir     RETURN_FINITE( fRet );
799cdf0e10cSrcweir }
800cdf0e10cSrcweir 
801cdf0e10cSrcweir 
802cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getSqrtpi( double fNum ) THROWDEF_RTE_IAE
803cdf0e10cSrcweir {
804cdf0e10cSrcweir     double fRet = sqrt( fNum * PI );
805cdf0e10cSrcweir     RETURN_FINITE( fRet );
806cdf0e10cSrcweir }
807cdf0e10cSrcweir 
808cdf0e10cSrcweir 
809cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getRandbetween( double fMin, double fMax ) THROWDEF_RTE_IAE
810cdf0e10cSrcweir {
811cdf0e10cSrcweir     fMin = ::rtl::math::round( fMin, 0, rtl_math_RoundingMode_Up );
812cdf0e10cSrcweir     fMax = ::rtl::math::round( fMax, 0, rtl_math_RoundingMode_Up );
813cdf0e10cSrcweir     if( fMin > fMax )
814cdf0e10cSrcweir         THROW_IAE;
815cdf0e10cSrcweir 
816cdf0e10cSrcweir     // fMax -> range
817cdf0e10cSrcweir     double fRet = fMax - fMin + 1.0;
818cdf0e10cSrcweir     fRet *= rand();
819cdf0e10cSrcweir     fRet /= (RAND_MAX + 1.0);
820cdf0e10cSrcweir     fRet += fMin;
821cdf0e10cSrcweir     fRet = floor( fRet );   // simple floor is sufficient here
822cdf0e10cSrcweir     RETURN_FINITE( fRet );
823cdf0e10cSrcweir }
824cdf0e10cSrcweir 
825cdf0e10cSrcweir 
826cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getGcd( constREFXPS& xOpt, const SEQSEQ( double )& aVLst, const SEQ( uno::Any )& aOptVLst ) THROWDEF_RTE_IAE
827cdf0e10cSrcweir {
828cdf0e10cSrcweir     ScaDoubleListGT0 aValList;
829cdf0e10cSrcweir 
830cdf0e10cSrcweir     aValList.Append( aVLst );
831cdf0e10cSrcweir     aValList.Append( aAnyConv, xOpt, aOptVLst );
832cdf0e10cSrcweir 
833cdf0e10cSrcweir     if( aValList.Count() == 0 )
834cdf0e10cSrcweir         return 0.0;
835cdf0e10cSrcweir 
836cdf0e10cSrcweir     const double*   p = aValList.First();
837cdf0e10cSrcweir     double          f = *p;
838cdf0e10cSrcweir 
839cdf0e10cSrcweir     p = aValList.Next();
840cdf0e10cSrcweir 
841cdf0e10cSrcweir     while( p )
842cdf0e10cSrcweir     {
843cdf0e10cSrcweir         f = GetGcd( *p, f );
844cdf0e10cSrcweir         p = aValList.Next();
845cdf0e10cSrcweir     }
846cdf0e10cSrcweir 
847cdf0e10cSrcweir     RETURN_FINITE( f );
848cdf0e10cSrcweir }
849cdf0e10cSrcweir 
850cdf0e10cSrcweir 
851cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getLcm( constREFXPS& xOpt, const SEQSEQ( double )& aVLst, const SEQ( uno::Any )& aOptVLst ) THROWDEF_RTE_IAE
852cdf0e10cSrcweir {
853cdf0e10cSrcweir     ScaDoubleListGE0 aValList;
854cdf0e10cSrcweir 
855cdf0e10cSrcweir     aValList.Append( aVLst );
856cdf0e10cSrcweir     aValList.Append( aAnyConv, xOpt, aOptVLst );
857cdf0e10cSrcweir 
858cdf0e10cSrcweir     if( aValList.Count() == 0 )
859cdf0e10cSrcweir         return 0.0;
860cdf0e10cSrcweir 
861cdf0e10cSrcweir     const double*   p = aValList.First();
862cdf0e10cSrcweir     double          f = *p;
863cdf0e10cSrcweir 
864cdf0e10cSrcweir     if( f == 0.0 )
865cdf0e10cSrcweir         return f;
866cdf0e10cSrcweir 
867cdf0e10cSrcweir     p = aValList.Next();
868cdf0e10cSrcweir 
869cdf0e10cSrcweir     while( p )
870cdf0e10cSrcweir     {
871cdf0e10cSrcweir         double      fTmp = *p;
872cdf0e10cSrcweir         if( f == 0.0 )
873cdf0e10cSrcweir             return f;
874cdf0e10cSrcweir         else
875cdf0e10cSrcweir             f = fTmp * f / GetGcd( fTmp, f );
876cdf0e10cSrcweir         p = aValList.Next();
877cdf0e10cSrcweir     }
878cdf0e10cSrcweir 
879cdf0e10cSrcweir     RETURN_FINITE( f );
880cdf0e10cSrcweir }
881cdf0e10cSrcweir 
882cdf0e10cSrcweir 
883cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getBesseli( double fNum, sal_Int32 nOrder ) THROWDEF_RTE_IAE_NCE
884cdf0e10cSrcweir {
885cdf0e10cSrcweir     double fRet = sca::analysis::BesselI( fNum, nOrder );
886cdf0e10cSrcweir     RETURN_FINITE( fRet );
887cdf0e10cSrcweir }
888cdf0e10cSrcweir 
889cdf0e10cSrcweir 
890cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getBesselj( double fNum, sal_Int32 nOrder ) THROWDEF_RTE_IAE_NCE
891cdf0e10cSrcweir {
892cdf0e10cSrcweir     double fRet = sca::analysis::BesselJ( fNum, nOrder );
893cdf0e10cSrcweir     RETURN_FINITE( fRet );
894cdf0e10cSrcweir }
895cdf0e10cSrcweir 
896cdf0e10cSrcweir 
897cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getBesselk( double fNum, sal_Int32 nOrder ) THROWDEF_RTE_IAE_NCE
898cdf0e10cSrcweir {
899cdf0e10cSrcweir     if( nOrder < 0 || fNum <= 0.0 )
900cdf0e10cSrcweir         THROW_IAE;
901cdf0e10cSrcweir 
902cdf0e10cSrcweir     double fRet = sca::analysis::BesselK( fNum, nOrder );
903cdf0e10cSrcweir     RETURN_FINITE( fRet );
904cdf0e10cSrcweir }
905cdf0e10cSrcweir 
906cdf0e10cSrcweir 
907cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getBessely( double fNum, sal_Int32 nOrder ) THROWDEF_RTE_IAE_NCE
908cdf0e10cSrcweir {
909cdf0e10cSrcweir     if( nOrder < 0 || fNum <= 0.0 )
910cdf0e10cSrcweir         THROW_IAE;
911cdf0e10cSrcweir 
912cdf0e10cSrcweir //  return yn( nOrder, fNum );
913cdf0e10cSrcweir     double fRet = sca::analysis::BesselY( fNum, nOrder );
914cdf0e10cSrcweir     RETURN_FINITE( fRet );
915cdf0e10cSrcweir }
916cdf0e10cSrcweir 
917cdf0e10cSrcweir 
918cdf0e10cSrcweir const double    SCA_MAX2        = 511.0;            // min. val for binary numbers (9 bits + sign)
919cdf0e10cSrcweir const double    SCA_MIN2        = -SCA_MAX2-1.0;    // min. val for binary numbers (9 bits + sign)
920cdf0e10cSrcweir const double    SCA_MAX8        = 536870911.0;      // max. val for octal numbers (29 bits + sign)
921cdf0e10cSrcweir const double    SCA_MIN8        = -SCA_MAX8-1.0;    // min. val for octal numbers (29 bits + sign)
922cdf0e10cSrcweir const double    SCA_MAX16       = 549755813888.0;   // max. val for hexadecimal numbers (39 bits + sign)
923cdf0e10cSrcweir const double    SCA_MIN16       = -SCA_MAX16-1.0;   // min. val for hexadecimal numbers (39 bits + sign)
924cdf0e10cSrcweir const sal_Int32 SCA_MAXPLACES   = 10;               // max. number of places
925cdf0e10cSrcweir 
926cdf0e10cSrcweir 
927cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getBin2Oct( constREFXPS& xOpt, const STRING& aNum, const ANY& rPlaces ) THROWDEF_RTE_IAE
928cdf0e10cSrcweir {
929cdf0e10cSrcweir     double fVal = ConvertToDec( aNum, 2, SCA_MAXPLACES );
930cdf0e10cSrcweir     sal_Int32 nPlaces = 0;
931cdf0e10cSrcweir     sal_Bool bUsePlaces = aAnyConv.getInt32( nPlaces, xOpt, rPlaces );
932cdf0e10cSrcweir     return ConvertFromDec( fVal, SCA_MIN8, SCA_MAX8, 8, nPlaces, SCA_MAXPLACES, bUsePlaces );
933cdf0e10cSrcweir }
934cdf0e10cSrcweir 
935cdf0e10cSrcweir 
936cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getBin2Dec( const STRING& aNum ) THROWDEF_RTE_IAE
937cdf0e10cSrcweir {
938cdf0e10cSrcweir     double fRet = ConvertToDec( aNum, 2, SCA_MAXPLACES );
939cdf0e10cSrcweir     RETURN_FINITE( fRet );
940cdf0e10cSrcweir }
941cdf0e10cSrcweir 
942cdf0e10cSrcweir 
943cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getBin2Hex( constREFXPS& xOpt, const STRING& aNum, const ANY& rPlaces ) THROWDEF_RTE_IAE
944cdf0e10cSrcweir {
945cdf0e10cSrcweir     double fVal = ConvertToDec( aNum, 2, SCA_MAXPLACES );
946cdf0e10cSrcweir     sal_Int32 nPlaces = 0;
947cdf0e10cSrcweir     sal_Bool bUsePlaces = aAnyConv.getInt32( nPlaces, xOpt, rPlaces );
948cdf0e10cSrcweir     return ConvertFromDec( fVal, SCA_MIN16, SCA_MAX16, 16, nPlaces, SCA_MAXPLACES, bUsePlaces );
949cdf0e10cSrcweir }
950cdf0e10cSrcweir 
951cdf0e10cSrcweir 
952cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getOct2Bin( constREFXPS& xOpt, const STRING& aNum, const ANY& rPlaces ) THROWDEF_RTE_IAE
953cdf0e10cSrcweir {
954cdf0e10cSrcweir     double fVal = ConvertToDec( aNum, 8, SCA_MAXPLACES );
955cdf0e10cSrcweir     sal_Int32 nPlaces = 0;
956cdf0e10cSrcweir     sal_Bool bUsePlaces = aAnyConv.getInt32( nPlaces, xOpt, rPlaces );
957cdf0e10cSrcweir     return ConvertFromDec( fVal, SCA_MIN2, SCA_MAX2, 2, nPlaces, SCA_MAXPLACES, bUsePlaces );
958cdf0e10cSrcweir }
959cdf0e10cSrcweir 
960cdf0e10cSrcweir 
961cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getOct2Dec( const STRING& aNum ) THROWDEF_RTE_IAE
962cdf0e10cSrcweir {
963cdf0e10cSrcweir     double fRet = ConvertToDec( aNum, 8, SCA_MAXPLACES );
964cdf0e10cSrcweir     RETURN_FINITE( fRet );
965cdf0e10cSrcweir }
966cdf0e10cSrcweir 
967cdf0e10cSrcweir 
968cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getOct2Hex( constREFXPS& xOpt, const STRING& aNum, const ANY& rPlaces ) THROWDEF_RTE_IAE
969cdf0e10cSrcweir {
970cdf0e10cSrcweir     double fVal = ConvertToDec( aNum, 8, SCA_MAXPLACES );
971cdf0e10cSrcweir     sal_Int32 nPlaces = 0;
972cdf0e10cSrcweir     sal_Bool bUsePlaces = aAnyConv.getInt32( nPlaces, xOpt, rPlaces );
973cdf0e10cSrcweir     return ConvertFromDec( fVal, SCA_MIN16, SCA_MAX16, 16, nPlaces, SCA_MAXPLACES, bUsePlaces );
974cdf0e10cSrcweir }
975cdf0e10cSrcweir 
976cdf0e10cSrcweir 
977cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getDec2Bin( constREFXPS& xOpt, sal_Int32 nNum, const ANY& rPlaces ) THROWDEF_RTE_IAE
978cdf0e10cSrcweir {
979cdf0e10cSrcweir     sal_Int32 nPlaces = 0;
980cdf0e10cSrcweir     sal_Bool bUsePlaces = aAnyConv.getInt32( nPlaces, xOpt, rPlaces );
981cdf0e10cSrcweir     return ConvertFromDec( nNum, SCA_MIN2, SCA_MAX2, 2, nPlaces, SCA_MAXPLACES, bUsePlaces );
982cdf0e10cSrcweir }
983cdf0e10cSrcweir 
984cdf0e10cSrcweir 
985cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getDec2Oct( constREFXPS& xOpt, sal_Int32 nNum, const ANY& rPlaces ) THROWDEF_RTE_IAE
986cdf0e10cSrcweir {
987cdf0e10cSrcweir     sal_Int32 nPlaces = 0;
988cdf0e10cSrcweir     sal_Bool bUsePlaces = aAnyConv.getInt32( nPlaces, xOpt, rPlaces );
989cdf0e10cSrcweir     return ConvertFromDec( nNum, SCA_MIN8, SCA_MAX8, 8, nPlaces, SCA_MAXPLACES, bUsePlaces );
990cdf0e10cSrcweir }
991cdf0e10cSrcweir 
992cdf0e10cSrcweir 
993cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getDec2Hex( constREFXPS& xOpt, double fNum, const ANY& rPlaces ) THROWDEF_RTE_IAE
994cdf0e10cSrcweir {
995cdf0e10cSrcweir     sal_Int32 nPlaces = 0;
996cdf0e10cSrcweir     sal_Bool bUsePlaces = aAnyConv.getInt32( nPlaces, xOpt, rPlaces );
997cdf0e10cSrcweir     return ConvertFromDec( fNum, SCA_MIN16, SCA_MAX16, 16, nPlaces, SCA_MAXPLACES, bUsePlaces );
998cdf0e10cSrcweir }
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir 
1001cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getHex2Bin( constREFXPS& xOpt, const STRING& aNum, const ANY& rPlaces ) THROWDEF_RTE_IAE
1002cdf0e10cSrcweir {
1003cdf0e10cSrcweir     double fVal = ConvertToDec( aNum, 16, SCA_MAXPLACES );
1004cdf0e10cSrcweir     sal_Int32 nPlaces = 0;
1005cdf0e10cSrcweir     sal_Bool bUsePlaces = aAnyConv.getInt32( nPlaces, xOpt, rPlaces );
1006cdf0e10cSrcweir     return ConvertFromDec( fVal, SCA_MIN2, SCA_MAX2, 2, nPlaces, SCA_MAXPLACES, bUsePlaces );
1007cdf0e10cSrcweir }
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir 
1010cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getHex2Dec( const STRING& aNum ) THROWDEF_RTE_IAE
1011cdf0e10cSrcweir {
1012cdf0e10cSrcweir     double fRet = ConvertToDec( aNum, 16, SCA_MAXPLACES );
1013cdf0e10cSrcweir     RETURN_FINITE( fRet );
1014cdf0e10cSrcweir }
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getHex2Oct( constREFXPS& xOpt, const STRING& aNum, const ANY& rPlaces ) THROWDEF_RTE_IAE
1018cdf0e10cSrcweir {
1019cdf0e10cSrcweir     double fVal = ConvertToDec( aNum, 16, SCA_MAXPLACES );
1020cdf0e10cSrcweir     sal_Int32 nPlaces = 0;
1021cdf0e10cSrcweir     sal_Bool bUsePlaces = aAnyConv.getInt32( nPlaces, xOpt, rPlaces );
1022cdf0e10cSrcweir     return ConvertFromDec( fVal, SCA_MIN8, SCA_MAX8, 8, nPlaces, SCA_MAXPLACES, bUsePlaces );
1023cdf0e10cSrcweir }
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir sal_Int32 SAL_CALL AnalysisAddIn::getDelta( constREFXPS& xOpt, double fNum1, const ANY& rNum2 ) THROWDEF_RTE_IAE
1027cdf0e10cSrcweir {
1028cdf0e10cSrcweir     return fNum1 == aAnyConv.getDouble( xOpt, rNum2, 0.0 );
1029cdf0e10cSrcweir }
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getErf( constREFXPS& xOpt, double fLL, const ANY& rUL ) THROWDEF_RTE_IAE
1033cdf0e10cSrcweir {
1034cdf0e10cSrcweir     double fUL, fRet;
1035cdf0e10cSrcweir     sal_Bool bContainsValue = aAnyConv.getDouble( fUL, xOpt, rUL );
1036cdf0e10cSrcweir 
1037cdf0e10cSrcweir     fRet = bContainsValue ? (Erf( fUL ) - Erf( fLL )) : Erf( fLL );
1038cdf0e10cSrcweir     RETURN_FINITE( fRet );
1039cdf0e10cSrcweir }
1040cdf0e10cSrcweir 
1041cdf0e10cSrcweir 
1042cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getErfc( double f ) THROWDEF_RTE_IAE
1043cdf0e10cSrcweir {
1044cdf0e10cSrcweir     double fRet = Erfc( f );
1045cdf0e10cSrcweir     RETURN_FINITE( fRet );
1046cdf0e10cSrcweir }
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir sal_Int32 SAL_CALL AnalysisAddIn::getGestep( constREFXPS& xOpt, double fNum, const ANY& rStep ) THROWDEF_RTE_IAE
1050cdf0e10cSrcweir {
1051cdf0e10cSrcweir     return fNum >= aAnyConv.getDouble( xOpt, rStep, 0.0 );
1052cdf0e10cSrcweir }
1053cdf0e10cSrcweir 
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getFactdouble( sal_Int32 nNum ) THROWDEF_RTE_IAE
1056cdf0e10cSrcweir {
1057cdf0e10cSrcweir     double fRet = FactDouble( nNum );
1058cdf0e10cSrcweir     RETURN_FINITE( fRet );
1059cdf0e10cSrcweir }
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getImabs( const STRING& aNum ) THROWDEF_RTE_IAE
1063cdf0e10cSrcweir {
1064cdf0e10cSrcweir     double fRet = Complex( aNum ).Abs();
1065cdf0e10cSrcweir     RETURN_FINITE( fRet );
1066cdf0e10cSrcweir }
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getImaginary( const STRING& aNum ) THROWDEF_RTE_IAE
1070cdf0e10cSrcweir {
1071cdf0e10cSrcweir     double fRet = Complex( aNum ).Imag();
1072cdf0e10cSrcweir     RETURN_FINITE( fRet );
1073cdf0e10cSrcweir }
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImpower( const STRING& aNum, double f ) THROWDEF_RTE_IAE
1077cdf0e10cSrcweir {
1078cdf0e10cSrcweir     Complex     z( aNum );
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir     z.Power( f );
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir     return z.GetString();
1083cdf0e10cSrcweir }
1084cdf0e10cSrcweir 
1085cdf0e10cSrcweir 
1086cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getImargument( const STRING& aNum ) THROWDEF_RTE_IAE
1087cdf0e10cSrcweir {
1088cdf0e10cSrcweir     double fRet = Complex( aNum ).Arg();
1089cdf0e10cSrcweir     RETURN_FINITE( fRet );
1090cdf0e10cSrcweir }
1091cdf0e10cSrcweir 
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImcos( const STRING& aNum ) THROWDEF_RTE_IAE
1094cdf0e10cSrcweir {
1095cdf0e10cSrcweir     Complex     z( aNum );
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir     z.Cos();
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir     return z.GetString();
1100cdf0e10cSrcweir }
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir 
1103cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImdiv( const STRING& aDivid, const STRING& aDivis ) THROWDEF_RTE_IAE
1104cdf0e10cSrcweir {
1105cdf0e10cSrcweir     Complex     z( aDivid );
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir     z.Div( Complex( aDivis ) );
1108cdf0e10cSrcweir 
1109cdf0e10cSrcweir     return z.GetString();
1110cdf0e10cSrcweir }
1111cdf0e10cSrcweir 
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImexp( const STRING& aNum ) THROWDEF_RTE_IAE
1114cdf0e10cSrcweir {
1115cdf0e10cSrcweir     Complex     z( aNum );
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir     z.Exp();
1118cdf0e10cSrcweir 
1119cdf0e10cSrcweir     return z.GetString();
1120cdf0e10cSrcweir }
1121cdf0e10cSrcweir 
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImconjugate( const STRING& aNum ) THROWDEF_RTE_IAE
1124cdf0e10cSrcweir {
1125cdf0e10cSrcweir     Complex     z( aNum );
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir     z.Conjugate();
1128cdf0e10cSrcweir 
1129cdf0e10cSrcweir     return z.GetString();
1130cdf0e10cSrcweir }
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImln( const STRING& aNum ) THROWDEF_RTE_IAE
1134cdf0e10cSrcweir {
1135cdf0e10cSrcweir     Complex     z( aNum );
1136cdf0e10cSrcweir 
1137cdf0e10cSrcweir     z.Ln();
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir     return z.GetString();
1140cdf0e10cSrcweir }
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir 
1143cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImlog10( const STRING& aNum ) THROWDEF_RTE_IAE
1144cdf0e10cSrcweir {
1145cdf0e10cSrcweir     Complex     z( aNum );
1146cdf0e10cSrcweir 
1147cdf0e10cSrcweir     z.Log10();
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir     return z.GetString();
1150cdf0e10cSrcweir }
1151cdf0e10cSrcweir 
1152cdf0e10cSrcweir 
1153cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImlog2( const STRING& aNum ) THROWDEF_RTE_IAE
1154cdf0e10cSrcweir {
1155cdf0e10cSrcweir     Complex     z( aNum );
1156cdf0e10cSrcweir 
1157cdf0e10cSrcweir     z.Log2();
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir     return z.GetString();
1160cdf0e10cSrcweir }
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir 
1163cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImproduct( constREFXPS&, const SEQSEQ( STRING )& aNum1, const SEQ( uno::Any )& aNL ) THROWDEF_RTE_IAE
1164cdf0e10cSrcweir {
1165cdf0e10cSrcweir     ComplexList     z_list;
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir     z_list.Append( aNum1, AH_IgnoreEmpty );
1168cdf0e10cSrcweir     z_list.Append( aNL, AH_IgnoreEmpty );
1169cdf0e10cSrcweir 
1170cdf0e10cSrcweir     const Complex*  p = z_list.First();
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir     if( !p )
1173cdf0e10cSrcweir         return Complex( 0 ).GetString();
1174cdf0e10cSrcweir 
1175cdf0e10cSrcweir     Complex         z( *p );
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir     for( p = z_list.Next() ; p ; p = z_list.Next() )
1178cdf0e10cSrcweir         z.Mult( *p );
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir     return z.GetString();
1181cdf0e10cSrcweir }
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir 
1184cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getImreal( const STRING& aNum ) THROWDEF_RTE_IAE
1185cdf0e10cSrcweir {
1186cdf0e10cSrcweir     double fRet = Complex( aNum ).Real();
1187cdf0e10cSrcweir     RETURN_FINITE( fRet );
1188cdf0e10cSrcweir }
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir 
1191cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImsin( const STRING& aNum ) THROWDEF_RTE_IAE
1192cdf0e10cSrcweir {
1193cdf0e10cSrcweir     Complex     z( aNum );
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir     z.Sin();
1196cdf0e10cSrcweir 
1197cdf0e10cSrcweir     return z.GetString();
1198cdf0e10cSrcweir }
1199cdf0e10cSrcweir 
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImsub( const STRING& aNum1, const STRING& aNum2 ) THROWDEF_RTE_IAE
1202cdf0e10cSrcweir {
1203cdf0e10cSrcweir     Complex     z( aNum1 );
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir     z.Sub( Complex( aNum2 ) );
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir     return z.GetString();
1208cdf0e10cSrcweir }
1209cdf0e10cSrcweir 
1210cdf0e10cSrcweir 
1211cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImsum( constREFXPS&, const SEQSEQ( STRING )& aNum1, const SEQ( CSS::uno::Any )& aFollowingPars ) THROWDEF_RTE_IAE
1212cdf0e10cSrcweir {
1213cdf0e10cSrcweir     ComplexList     z_list;
1214cdf0e10cSrcweir 
1215cdf0e10cSrcweir     z_list.Append( aNum1, AH_IgnoreEmpty );
1216cdf0e10cSrcweir     z_list.Append( aFollowingPars, AH_IgnoreEmpty );
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir     const Complex*  p = z_list.First();
1219cdf0e10cSrcweir 
1220cdf0e10cSrcweir     if( !p )
1221cdf0e10cSrcweir         return Complex( 0 ).GetString();
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir     Complex         z( *p );
1224cdf0e10cSrcweir 
1225cdf0e10cSrcweir     for( p = z_list.Next() ; p ; p = z_list.Next() )
1226cdf0e10cSrcweir         z.Add( *p );
1227cdf0e10cSrcweir 
1228cdf0e10cSrcweir     return z.GetString();
1229cdf0e10cSrcweir }
1230cdf0e10cSrcweir 
1231cdf0e10cSrcweir 
1232cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getImsqrt( const STRING& aNum ) THROWDEF_RTE_IAE
1233cdf0e10cSrcweir {
1234cdf0e10cSrcweir     Complex     z( aNum );
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir //  z.Power( 0.5 );
1237cdf0e10cSrcweir     z.Sqrt();
1238cdf0e10cSrcweir 
1239cdf0e10cSrcweir     return z.GetString();
1240cdf0e10cSrcweir }
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir STRING SAL_CALL AnalysisAddIn::getComplex( double fR, double fI, const ANY& rSuff ) THROWDEF_RTE_IAE
1244cdf0e10cSrcweir {
1245cdf0e10cSrcweir     sal_Bool    bi;
1246cdf0e10cSrcweir 
1247cdf0e10cSrcweir     switch( rSuff.getValueTypeClass() )
1248cdf0e10cSrcweir     {
1249cdf0e10cSrcweir         case uno::TypeClass_VOID:
1250cdf0e10cSrcweir             bi = sal_True;
1251cdf0e10cSrcweir             break;
1252cdf0e10cSrcweir         case uno::TypeClass_STRING:
1253cdf0e10cSrcweir             {
1254cdf0e10cSrcweir             const STRING*   pSuff = ( const STRING* ) rSuff.getValue();
1255cdf0e10cSrcweir             bi = pSuff->compareToAscii( "i" ) == 0 || pSuff->getLength() == 0;
1256cdf0e10cSrcweir             if( !bi && pSuff->compareToAscii( "j" ) != 0 )
1257cdf0e10cSrcweir                 THROW_IAE;
1258cdf0e10cSrcweir             }
1259cdf0e10cSrcweir             break;
1260cdf0e10cSrcweir         default:
1261cdf0e10cSrcweir             THROW_IAE;
1262cdf0e10cSrcweir     }
1263cdf0e10cSrcweir 
1264cdf0e10cSrcweir     return Complex( fR, fI, bi ? 'i' : 'j' ).GetString();
1265cdf0e10cSrcweir }
1266cdf0e10cSrcweir 
1267cdf0e10cSrcweir 
1268cdf0e10cSrcweir double SAL_CALL AnalysisAddIn::getConvert( double f, const STRING& aFU, const STRING& aTU ) THROWDEF_RTE_IAE
1269cdf0e10cSrcweir {
1270cdf0e10cSrcweir     if( !pCDL )
1271cdf0e10cSrcweir         pCDL = new ConvertDataList();
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir     double fRet = pCDL->Convert( f, aFU, aTU );
1274cdf0e10cSrcweir     RETURN_FINITE( fRet );
1275cdf0e10cSrcweir }
1276cdf0e10cSrcweir 
1277cdf0e10cSrcweir 
1278