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