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