1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "analysis.hxx"
22 #include <comphelper/processfactory.hxx>
23 #include <cppuhelper/factory.hxx>
24 #include <osl/diagnose.h>
25 #include <rtl/ustrbuf.hxx>
26 #include <rtl/math.hxx>
27 #include <sal/macros.h>
30 #include <tools/resmgr.hxx>
31 #include <tools/rcid.h>
32 #include "analysis.hrc"
35 #define ADDIN_SERVICE "com.sun.star.sheet.AddIn"
36 #define MY_SERVICE "com.sun.star.sheet.addin.Analysis"
37 #define MY_IMPLNAME "com.sun.star.sheet.addin.AnalysisImpl"
39 using namespace ::com::sun::star
;
42 extern "C" SAL_DLLPUBLIC_EXPORT
void* SAL_CALL
analysis_component_getFactory(
43 const sal_Char
* pImplName
, void* pServiceManager
, void* /*pRegistryKey*/ )
47 if( pServiceManager
&& OUString::createFromAscii( pImplName
) == AnalysisAddIn::getImplementationName_Static() )
49 uno::Reference
< lang::XSingleServiceFactory
> xFactory( cppu::createOneInstanceFactory(
50 reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
),
51 AnalysisAddIn::getImplementationName_Static(),
52 AnalysisAddIn_CreateInstance
,
53 AnalysisAddIn::getSupportedServiceNames_Static() ) );
58 pRet
= xFactory
.get();
66 //------------------------------------------------------------------------
68 // "normal" service implementation
70 //------------------------------------------------------------------------
73 ResMgr
& AnalysisAddIn::GetResMgr( void ) throw( uno::RuntimeException
)
77 InitData(); // try to get resource manager
80 throw uno::RuntimeException();
87 OUString
AnalysisAddIn::GetDisplFuncStr( sal_uInt16 nFuncNum
) throw( uno::RuntimeException
)
89 return String( AnalysisRscStrLoader( RID_ANALYSIS_FUNCTION_NAMES
, nFuncNum
, GetResMgr() ).GetString() );
93 class AnalysisResourcePublisher
: public Resource
96 AnalysisResourcePublisher( const AnalysisResId
& rId
) : Resource( rId
) {}
97 sal_Bool
IsAvailableRes( const ResId
& rId
) const { return Resource::IsAvailableRes( rId
); }
98 void FreeResource() { Resource::FreeResource(); }
102 class AnalysisFuncRes
: public Resource
105 AnalysisFuncRes( ResId
& rRes
, ResMgr
& rResMgr
, sal_uInt16 nInd
, OUString
& rRet
);
109 AnalysisFuncRes::AnalysisFuncRes( ResId
& rRes
, ResMgr
& rResMgr
, sal_uInt16 nInd
, OUString
& rRet
) : Resource( rRes
)
111 rRet
= String( AnalysisResId( nInd
, rResMgr
) );
117 OUString
AnalysisAddIn::GetFuncDescrStr( sal_uInt16 nResId
, sal_uInt16 nStrIndex
) throw( uno::RuntimeException
)
120 AnalysisResourcePublisher
aResPubl( AnalysisResId( RID_ANALYSIS_FUNCTION_DESCRIPTIONS
, GetResMgr() ) );
121 AnalysisResId
aRes( nResId
, GetResMgr() );
122 aRes
.SetRT( RSC_RESOURCE
);
123 if( aResPubl
.IsAvailableRes( aRes
) )
125 AnalysisFuncRes
aSubRes( aRes
, GetResMgr(), nStrIndex
, aRet
);
128 aResPubl
.FreeResource();
134 void AnalysisAddIn::InitData( void )
139 OString
aModName( "analysis" );
140 pResMgr
= ResMgr::CreateResMgr( aModName
.getStr(), LanguageTag( aFuncLoc
) );
146 pFD
= new FuncDataList( *pResMgr
);
158 AnalysisAddIn::AnalysisAddIn( const uno::Reference
< uno::XComponentContext
>& xContext
) :
161 pFactDoubles( NULL
),
169 AnalysisAddIn::~AnalysisAddIn()
175 delete[] pFactDoubles
;
181 delete[] pDefLocales
;
185 sal_Int32
AnalysisAddIn::getDateMode(
186 const uno::Reference
< beans::XPropertySet
>& xPropSet
,
187 const uno::Any
& rAny
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
189 sal_Int32 nMode
= aAnyConv
.getInt32( xPropSet
, rAny
, 0 );
190 if( (nMode
< 0) || (nMode
> 4) )
191 throw lang::IllegalArgumentException();
197 //-----------------------------------------------------------------------------
200 #define MAXFACTDOUBLE 300
202 double AnalysisAddIn::FactDouble( sal_Int32 nNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
204 if( nNum
< 0 || nNum
> MAXFACTDOUBLE
)
205 throw lang::IllegalArgumentException();
209 pFactDoubles
= new double[ MAXFACTDOUBLE
+ 1 ];
211 pFactDoubles
[ 0 ] = 1.0; // by default
216 pFactDoubles
[ 1 ] = fOdd
;
217 pFactDoubles
[ 2 ] = fEven
;
219 sal_Bool bOdd
= sal_True
;
221 for( sal_uInt16 nCnt
= 3 ; nCnt
<= MAXFACTDOUBLE
; nCnt
++ )
226 pFactDoubles
[ nCnt
] = fOdd
;
231 pFactDoubles
[ nCnt
] = fEven
;
239 return pFactDoubles
[ nNum
];
243 OUString
AnalysisAddIn::getImplementationName_Static()
245 return OUString( MY_IMPLNAME
);
249 uno::Sequence
< OUString
> AnalysisAddIn::getSupportedServiceNames_Static()
251 uno::Sequence
< OUString
> aRet(2);
252 OUString
* pArray
= aRet
.getArray();
253 pArray
[0] = OUString( ADDIN_SERVICE
);
254 pArray
[1] = OUString( MY_SERVICE
);
259 uno::Reference
< uno::XInterface
> SAL_CALL
AnalysisAddIn_CreateInstance(
260 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceFact
)
262 static uno::Reference
< uno::XInterface
> xInst
= (cppu::OWeakObject
*) new AnalysisAddIn( comphelper::getComponentContext(xServiceFact
) );
269 OUString SAL_CALL
AnalysisAddIn::getServiceName() throw( uno::RuntimeException
)
271 // name of specific AddIn service
272 return OUString( MY_SERVICE
);
278 OUString SAL_CALL
AnalysisAddIn::getImplementationName() throw( uno::RuntimeException
)
280 return getImplementationName_Static();
284 sal_Bool SAL_CALL
AnalysisAddIn::supportsService( const OUString
& aName
) throw( uno::RuntimeException
)
286 return aName
.compareToAscii( ADDIN_SERVICE
) == 0 || aName
.compareToAscii( MY_SERVICE
) == 0;
290 uno::Sequence
< OUString
> SAL_CALL
AnalysisAddIn::getSupportedServiceNames() throw( uno::RuntimeException
)
292 return getSupportedServiceNames_Static();
298 void SAL_CALL
AnalysisAddIn::setLocale( const lang::Locale
& eLocale
) throw( uno::RuntimeException
)
302 InitData(); // change of locale invalidates resources!
305 lang::Locale SAL_CALL
AnalysisAddIn::getLocale() throw( uno::RuntimeException
)
313 OUString SAL_CALL
AnalysisAddIn::getProgrammaticFuntionName( const OUString
& ) throw( uno::RuntimeException
)
316 // (but should be implemented for other uses of the AddIn service)
322 OUString SAL_CALL
AnalysisAddIn::getDisplayFunctionName( const OUString
& aProgrammaticName
) throw( uno::RuntimeException
)
326 const FuncData
* p
= pFD
->Get( aProgrammaticName
);
329 aRet
= GetDisplFuncStr( p
->GetUINameID() );
335 aRet
= "UNKNOWNFUNC_" + aProgrammaticName
;
342 OUString SAL_CALL
AnalysisAddIn::getFunctionDescription( const OUString
& aProgrammaticName
) throw( uno::RuntimeException
)
346 const FuncData
* p
= pFD
->Get( aProgrammaticName
);
348 aRet
= GetFuncDescrStr( p
->GetDescrID(), 1 );
354 OUString SAL_CALL
AnalysisAddIn::getDisplayArgumentName( const OUString
& aName
, sal_Int32 nArg
) throw( uno::RuntimeException
)
358 const FuncData
* p
= pFD
->Get( aName
);
359 if( p
&& nArg
<= 0xFFFF )
361 sal_uInt16 nStr
= p
->GetStrIndex( sal_uInt16( nArg
) );
363 aRet
= GetFuncDescrStr( p
->GetDescrID(), nStr
);
372 OUString SAL_CALL
AnalysisAddIn::getArgumentDescription( const OUString
& aName
, sal_Int32 nArg
) throw( uno::RuntimeException
)
376 const FuncData
* p
= pFD
->Get( aName
);
377 if( p
&& nArg
<= 0xFFFF )
379 sal_uInt16 nStr
= p
->GetStrIndex( sal_uInt16( nArg
) );
381 aRet
= GetFuncDescrStr( p
->GetDescrID(), nStr
+ 1 );
383 aRet
= "for internal use only";
390 static const OUString
pDefCatName("Add-In");
393 OUString SAL_CALL
AnalysisAddIn::getProgrammaticCategoryName( const OUString
& aName
) throw( uno::RuntimeException
)
395 // return non-translated strings
396 // return OUString( "Add-In" );
397 const FuncData
* p
= pFD
->Get( aName
);
401 switch( p
->GetCategory() )
403 case FDCat_DateTime
: aRet
= "Date&Time"; break;
404 case FDCat_Finance
: aRet
= "Financial"; break;
405 case FDCat_Inf
: aRet
= "Information"; break;
406 case FDCat_Math
: aRet
= "Mathematical"; break;
407 case FDCat_Tech
: aRet
= "Technical"; break;
409 aRet
= pDefCatName
; break;
419 OUString SAL_CALL
AnalysisAddIn::getDisplayCategoryName( const OUString
& aProgrammaticFunctionName
) throw( uno::RuntimeException
)
421 // return translated strings, not used for predefined categories
422 // return OUString( "Add-In" );
423 const FuncData
* p
= pFD
->Get( aProgrammaticFunctionName
);
427 switch( p
->GetCategory() )
429 case FDCat_DateTime
: aRet
= "Date&Time"; break;
430 case FDCat_Finance
: aRet
= "Financial"; break;
431 case FDCat_Inf
: aRet
= "Information"; break;
432 case FDCat_Math
: aRet
= "Mathematical"; break;
433 case FDCat_Tech
: aRet
= "Technical"; break;
435 aRet
= pDefCatName
; break;
445 static const sal_Char
* pLang
[] = { "de", "en" };
446 static const sal_Char
* pCoun
[] = { "DE", "US" };
447 static const sal_uInt32 nNumOfLoc
= SAL_N_ELEMENTS(pLang
);
450 void AnalysisAddIn::InitDefLocales( void )
452 pDefLocales
= new lang::Locale
[ nNumOfLoc
];
454 for( sal_uInt32 n
= 0 ; n
< nNumOfLoc
; n
++ )
456 pDefLocales
[ n
].Language
= OUString::createFromAscii( pLang
[ n
] );
457 pDefLocales
[ n
].Country
= OUString::createFromAscii( pCoun
[ n
] );
462 inline const lang::Locale
& AnalysisAddIn::GetLocale( sal_uInt32 nInd
)
467 if( nInd
< sizeof( pLang
) )
468 return pDefLocales
[ nInd
];
474 uno::Sequence
< sheet::LocalizedName
> SAL_CALL
AnalysisAddIn::getCompatibilityNames( const OUString
& aProgrammaticName
) throw( uno::RuntimeException
)
476 const FuncData
* p
= pFD
->Get( aProgrammaticName
);
479 return uno::Sequence
< sheet::LocalizedName
>( 0 );
481 const StringList
& r
= p
->GetCompNameList();
482 sal_uInt32 nCount
= r
.Count();
484 uno::Sequence
< sheet::LocalizedName
> aRet( nCount
);
486 sheet::LocalizedName
* pArray
= aRet
.getArray();
488 for( sal_uInt32 n
= 0 ; n
< nCount
; n
++ )
490 pArray
[ n
] = sheet::LocalizedName( GetLocale( n
), *r
.Get( n
) );
503 sal_Int32 SAL_CALL
AnalysisAddIn::getWorkday( const uno::Reference
< beans::XPropertySet
>& xOptions
,
504 sal_Int32 nDate
, sal_Int32 nDays
, const uno::Any
& aHDay
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
509 sal_Int32 nNullDate
= GetNullDate( xOptions
);
511 SortedIndividualInt32List aSrtLst
;
513 aSrtLst
.InsertHolidayList( aAnyConv
, xOptions
, aHDay
, nNullDate
, sal_False
);
515 sal_Int32 nActDate
= nDate
+ nNullDate
;
519 if( GetDayOfWeek( nActDate
) == 5 )
520 // when starting on Saturday, assuming we're starting on Sunday to get the jump over the weekend
527 if( GetDayOfWeek( nActDate
) < 5 )
529 if( !aSrtLst
.Find( nActDate
) )
533 nActDate
++; // jump over weekend
538 if( GetDayOfWeek( nActDate
) == 6 )
539 // when starting on Sunday, assuming we're starting on Saturday to get the jump over the weekend
546 if( GetDayOfWeek( nActDate
) < 5 )
548 if( !aSrtLst
.Find( nActDate
) )
552 nActDate
--; // jump over weekend
556 return nActDate
- nNullDate
;
564 double SAL_CALL
AnalysisAddIn::getYearfrac( const uno::Reference
< beans::XPropertySet
>& xOpt
,
565 sal_Int32 nStartDate
, sal_Int32 nEndDate
, const uno::Any
& rMode
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
567 double fRet
= GetYearFrac( xOpt
, nStartDate
, nEndDate
, getDateMode( xOpt
, rMode
) );
568 RETURN_FINITE( fRet
);
572 sal_Int32 SAL_CALL
AnalysisAddIn::getEdate( const uno::Reference
< beans::XPropertySet
>& xOpt
, sal_Int32 nStartDate
, sal_Int32 nMonths
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
574 sal_Int32 nNullDate
= GetNullDate( xOpt
);
575 ScaDate
aDate( nNullDate
, nStartDate
, 5 );
576 aDate
.addMonths( nMonths
);
577 return aDate
.getDate( nNullDate
);
581 sal_Int32 SAL_CALL
AnalysisAddIn::getWeeknum( const uno::Reference
< beans::XPropertySet
>& xOpt
, sal_Int32 nDate
, sal_Int32 nMode
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
583 nDate
+= GetNullDate( xOpt
);
585 sal_uInt16 nDay
, nMonth
, nYear
;
586 DaysToDate( nDate
, nDay
, nMonth
, nYear
);
588 sal_Int32 nFirstInYear
= DateToDays( 1, 1, nYear
);
589 sal_uInt16 nFirstDayInYear
= GetDayOfWeek( nFirstInYear
);
591 return ( nDate
- nFirstInYear
+ ( ( nMode
== 1 )? ( nFirstDayInYear
+ 1 ) % 7 : nFirstDayInYear
) ) / 7 + 1;
595 sal_Int32 SAL_CALL
AnalysisAddIn::getEomonth( const uno::Reference
< beans::XPropertySet
>& xOpt
, sal_Int32 nDate
, sal_Int32 nMonths
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
597 sal_Int32 nNullDate
= GetNullDate( xOpt
);
599 sal_uInt16 nDay
, nMonth
, nYear
;
600 DaysToDate( nDate
, nDay
, nMonth
, nYear
);
602 sal_Int32 nNewMonth
= nMonth
+ nMonths
;
606 nYear
= sal::static_int_cast
<sal_uInt16
>( nYear
+ ( nNewMonth
/ 12 ) );
609 else if( nNewMonth
< 1 )
611 nNewMonth
= -nNewMonth
;
612 nYear
= sal::static_int_cast
<sal_uInt16
>( nYear
- ( nNewMonth
/ 12 ) );
615 nNewMonth
= 12 - nNewMonth
;
618 return DateToDays( DaysInMonth( sal_uInt16( nNewMonth
), nYear
), sal_uInt16( nNewMonth
), nYear
) - nNullDate
;
622 sal_Int32 SAL_CALL
AnalysisAddIn::getNetworkdays( const uno::Reference
< beans::XPropertySet
>& xOpt
,
623 sal_Int32 nStartDate
, sal_Int32 nEndDate
, const uno::Any
& aHDay
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
625 sal_Int32 nNullDate
= GetNullDate( xOpt
);
627 SortedIndividualInt32List aSrtLst
;
629 aSrtLst
.InsertHolidayList( aAnyConv
, xOpt
, aHDay
, nNullDate
, sal_False
);
631 sal_Int32 nActDate
= nStartDate
+ nNullDate
;
632 sal_Int32 nStopDate
= nEndDate
+ nNullDate
;
635 if( nActDate
<= nStopDate
)
637 while( nActDate
<= nStopDate
)
639 if( GetDayOfWeek( nActDate
) < 5 && !aSrtLst
.Find( nActDate
) )
647 while( nActDate
>= nStopDate
)
649 if( GetDayOfWeek( nActDate
) < 5 && !aSrtLst
.Find( nActDate
) )
660 sal_Int32 SAL_CALL
AnalysisAddIn::getIseven( sal_Int32 nVal
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
662 return ( nVal
& 0x00000001 )? 0 : 1;
666 sal_Int32 SAL_CALL
AnalysisAddIn::getIsodd( sal_Int32 nVal
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
668 return ( nVal
& 0x00000001 )? 1 : 0;
672 AnalysisAddIn::getMultinomial( const uno::Reference
< beans::XPropertySet
>& xOpt
, const uno::Sequence
< uno::Sequence
< sal_Int32
> >& aVLst
,
673 const uno::Sequence
< uno::Any
>& aOptVLst
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
675 ScaDoubleListGE0 aValList
;
677 aValList
.Append( aVLst
);
678 aValList
.Append( aAnyConv
, xOpt
, aOptVLst
);
680 if( aValList
.Count() == 0 )
686 for( const double *p
= aValList
.First(); p
; p
= aValList
.Next() )
688 double n
= (*p
>= 0.0) ? rtl::math::approxFloor( *p
) : rtl::math::approxCeil( *p
);
690 throw lang::IllegalArgumentException();
695 fRet
*= BinomialCoefficient(nZ
, n
);
698 RETURN_FINITE( fRet
);
702 double SAL_CALL
AnalysisAddIn::getSeriessum( double fX
, double fN
, double fM
, const uno::Sequence
< uno::Sequence
< double > >& aCoeffList
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
706 // #i32269# 0^0 is undefined, Excel returns #NUM! error
707 if( fX
== 0.0 && fN
== 0 )
708 throw uno::RuntimeException();
713 sal_Int32 nE1
= aCoeffList
.getLength();
716 for( n1
= 0 ; n1
< nE1
; n1
++ )
718 const uno::Sequence
< double >& rList
= aCoeffList
[ n1
];
719 nE2
= rList
.getLength();
720 const double* pList
= rList
.getConstArray();
722 for( n2
= 0 ; n2
< nE2
; n2
++ )
724 fRet
+= pList
[ n2
] * pow( fX
, fN
);
731 RETURN_FINITE( fRet
);
735 double SAL_CALL
AnalysisAddIn::getQuotient( double fNum
, double fDenom
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
738 if( (fNum
< 0) != (fDenom
< 0) )
739 fRet
= ::rtl::math::approxCeil( fNum
/ fDenom
);
741 fRet
= ::rtl::math::approxFloor( fNum
/ fDenom
);
742 RETURN_FINITE( fRet
);
746 double SAL_CALL
AnalysisAddIn::getMround( double fNum
, double fMult
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
751 double fRet
= fMult
* ::rtl::math::round( fNum
/ fMult
);
752 RETURN_FINITE( fRet
);
756 double SAL_CALL
AnalysisAddIn::getSqrtpi( double fNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
758 double fRet
= sqrt( fNum
* PI
);
759 RETURN_FINITE( fRet
);
763 double SAL_CALL
AnalysisAddIn::getRandbetween( double fMin
, double fMax
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
765 fMin
= ::rtl::math::round( fMin
, 0, rtl_math_RoundingMode_Up
);
766 fMax
= ::rtl::math::round( fMax
, 0, rtl_math_RoundingMode_Up
);
768 throw lang::IllegalArgumentException();
771 double fRet
= fMax
- fMin
+ 1.0;
773 fRet
/= (RAND_MAX
+ 1.0);
775 fRet
= floor( fRet
); // simple floor is sufficient here
776 RETURN_FINITE( fRet
);
780 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
)
782 ScaDoubleListGT0 aValList
;
784 aValList
.Append( aVLst
);
785 aValList
.Append( aAnyConv
, xOpt
, aOptVLst
);
787 if( aValList
.Count() == 0 )
790 const double* p
= aValList
.First();
805 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
)
807 ScaDoubleListGE0 aValList
;
809 aValList
.Append( aVLst
);
810 aValList
.Append( aAnyConv
, xOpt
, aOptVLst
);
812 if( aValList
.Count() == 0 )
815 const double* p
= aValList
.First();
829 f
= fTmp
* f
/ GetGcd( fTmp
, f
);
837 double SAL_CALL
AnalysisAddIn::getBesseli( double fNum
, sal_Int32 nOrder
) throw( uno::RuntimeException
, lang::IllegalArgumentException
, sheet::NoConvergenceException
)
839 double fRet
= sca::analysis::BesselI( fNum
, nOrder
);
840 RETURN_FINITE( fRet
);
844 double SAL_CALL
AnalysisAddIn::getBesselj( double fNum
, sal_Int32 nOrder
) throw( uno::RuntimeException
, lang::IllegalArgumentException
, sheet::NoConvergenceException
)
846 double fRet
= sca::analysis::BesselJ( fNum
, nOrder
);
847 RETURN_FINITE( fRet
);
851 double SAL_CALL
AnalysisAddIn::getBesselk( double fNum
, sal_Int32 nOrder
) throw( uno::RuntimeException
, lang::IllegalArgumentException
, sheet::NoConvergenceException
)
853 if( nOrder
< 0 || fNum
<= 0.0 )
854 throw lang::IllegalArgumentException();
856 double fRet
= sca::analysis::BesselK( fNum
, nOrder
);
857 RETURN_FINITE( fRet
);
861 double SAL_CALL
AnalysisAddIn::getBessely( double fNum
, sal_Int32 nOrder
) throw( uno::RuntimeException
, lang::IllegalArgumentException
, sheet::NoConvergenceException
)
863 if( nOrder
< 0 || fNum
<= 0.0 )
864 throw lang::IllegalArgumentException();
866 double fRet
= sca::analysis::BesselY( fNum
, nOrder
);
867 RETURN_FINITE( fRet
);
871 const double SCA_MAX2
= 511.0; // min. val for binary numbers (9 bits + sign)
872 const double SCA_MIN2
= -SCA_MAX2
-1.0; // min. val for binary numbers (9 bits + sign)
873 const double SCA_MAX8
= 536870911.0; // max. val for octal numbers (29 bits + sign)
874 const double SCA_MIN8
= -SCA_MAX8
-1.0; // min. val for octal numbers (29 bits + sign)
875 const double SCA_MAX16
= 549755813888.0; // max. val for hexadecimal numbers (39 bits + sign)
876 const double SCA_MIN16
= -SCA_MAX16
-1.0; // min. val for hexadecimal numbers (39 bits + sign)
877 const sal_Int32 SCA_MAXPLACES
= 10; // max. number of places
880 OUString SAL_CALL
AnalysisAddIn::getBin2Oct( const uno::Reference
< beans::XPropertySet
>& xOpt
, const OUString
& aNum
, const uno::Any
& rPlaces
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
882 double fVal
= ConvertToDec( aNum
, 2, SCA_MAXPLACES
);
883 sal_Int32 nPlaces
= 0;
884 sal_Bool bUsePlaces
= aAnyConv
.getInt32( nPlaces
, xOpt
, rPlaces
);
885 return ConvertFromDec( fVal
, SCA_MIN8
, SCA_MAX8
, 8, nPlaces
, SCA_MAXPLACES
, bUsePlaces
);
889 double SAL_CALL
AnalysisAddIn::getBin2Dec( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
891 double fRet
= ConvertToDec( aNum
, 2, SCA_MAXPLACES
);
892 RETURN_FINITE( fRet
);
896 OUString SAL_CALL
AnalysisAddIn::getBin2Hex( const uno::Reference
< beans::XPropertySet
>& xOpt
, const OUString
& aNum
, const uno::Any
& rPlaces
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
898 double fVal
= ConvertToDec( aNum
, 2, SCA_MAXPLACES
);
899 sal_Int32 nPlaces
= 0;
900 sal_Bool bUsePlaces
= aAnyConv
.getInt32( nPlaces
, xOpt
, rPlaces
);
901 return ConvertFromDec( fVal
, SCA_MIN16
, SCA_MAX16
, 16, nPlaces
, SCA_MAXPLACES
, bUsePlaces
);
905 OUString SAL_CALL
AnalysisAddIn::getOct2Bin( const uno::Reference
< beans::XPropertySet
>& xOpt
, const OUString
& aNum
, const uno::Any
& rPlaces
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
907 double fVal
= ConvertToDec( aNum
, 8, SCA_MAXPLACES
);
908 sal_Int32 nPlaces
= 0;
909 sal_Bool bUsePlaces
= aAnyConv
.getInt32( nPlaces
, xOpt
, rPlaces
);
910 return ConvertFromDec( fVal
, SCA_MIN2
, SCA_MAX2
, 2, nPlaces
, SCA_MAXPLACES
, bUsePlaces
);
914 double SAL_CALL
AnalysisAddIn::getOct2Dec( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
916 double fRet
= ConvertToDec( aNum
, 8, SCA_MAXPLACES
);
917 RETURN_FINITE( fRet
);
921 OUString SAL_CALL
AnalysisAddIn::getOct2Hex( const uno::Reference
< beans::XPropertySet
>& xOpt
, const OUString
& aNum
, const uno::Any
& rPlaces
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
923 double fVal
= ConvertToDec( aNum
, 8, SCA_MAXPLACES
);
924 sal_Int32 nPlaces
= 0;
925 sal_Bool bUsePlaces
= aAnyConv
.getInt32( nPlaces
, xOpt
, rPlaces
);
926 return ConvertFromDec( fVal
, SCA_MIN16
, SCA_MAX16
, 16, nPlaces
, SCA_MAXPLACES
, bUsePlaces
);
930 OUString SAL_CALL
AnalysisAddIn::getDec2Bin( const uno::Reference
< beans::XPropertySet
>& xOpt
, sal_Int32 nNum
, const uno::Any
& rPlaces
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
932 sal_Int32 nPlaces
= 0;
933 sal_Bool bUsePlaces
= aAnyConv
.getInt32( nPlaces
, xOpt
, rPlaces
);
934 return ConvertFromDec( nNum
, SCA_MIN2
, SCA_MAX2
, 2, nPlaces
, SCA_MAXPLACES
, bUsePlaces
);
938 OUString SAL_CALL
AnalysisAddIn::getDec2Oct( const uno::Reference
< beans::XPropertySet
>& xOpt
, sal_Int32 nNum
, const uno::Any
& rPlaces
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
940 sal_Int32 nPlaces
= 0;
941 sal_Bool bUsePlaces
= aAnyConv
.getInt32( nPlaces
, xOpt
, rPlaces
);
942 return ConvertFromDec( nNum
, SCA_MIN8
, SCA_MAX8
, 8, nPlaces
, SCA_MAXPLACES
, bUsePlaces
);
946 OUString SAL_CALL
AnalysisAddIn::getDec2Hex( const uno::Reference
< beans::XPropertySet
>& xOpt
, double fNum
, const uno::Any
& rPlaces
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
948 sal_Int32 nPlaces
= 0;
949 sal_Bool bUsePlaces
= aAnyConv
.getInt32( nPlaces
, xOpt
, rPlaces
);
950 return ConvertFromDec( fNum
, SCA_MIN16
, SCA_MAX16
, 16, nPlaces
, SCA_MAXPLACES
, bUsePlaces
);
954 OUString SAL_CALL
AnalysisAddIn::getHex2Bin( const uno::Reference
< beans::XPropertySet
>& xOpt
, const OUString
& aNum
, const uno::Any
& rPlaces
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
956 double fVal
= ConvertToDec( aNum
, 16, SCA_MAXPLACES
);
957 sal_Int32 nPlaces
= 0;
958 sal_Bool bUsePlaces
= aAnyConv
.getInt32( nPlaces
, xOpt
, rPlaces
);
959 return ConvertFromDec( fVal
, SCA_MIN2
, SCA_MAX2
, 2, nPlaces
, SCA_MAXPLACES
, bUsePlaces
);
963 double SAL_CALL
AnalysisAddIn::getHex2Dec( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
965 double fRet
= ConvertToDec( aNum
, 16, SCA_MAXPLACES
);
966 RETURN_FINITE( fRet
);
970 OUString SAL_CALL
AnalysisAddIn::getHex2Oct( const uno::Reference
< beans::XPropertySet
>& xOpt
, const OUString
& aNum
, const uno::Any
& rPlaces
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
972 double fVal
= ConvertToDec( aNum
, 16, SCA_MAXPLACES
);
973 sal_Int32 nPlaces
= 0;
974 sal_Bool bUsePlaces
= aAnyConv
.getInt32( nPlaces
, xOpt
, rPlaces
);
975 return ConvertFromDec( fVal
, SCA_MIN8
, SCA_MAX8
, 8, nPlaces
, SCA_MAXPLACES
, bUsePlaces
);
979 sal_Int32 SAL_CALL
AnalysisAddIn::getDelta( const uno::Reference
< beans::XPropertySet
>& xOpt
, double fNum1
, const uno::Any
& rNum2
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
981 return fNum1
== aAnyConv
.getDouble( xOpt
, rNum2
, 0.0 );
985 double SAL_CALL
AnalysisAddIn::getErf( const uno::Reference
< beans::XPropertySet
>& xOpt
, double fLL
, const uno::Any
& rUL
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
988 sal_Bool bContainsValue
= aAnyConv
.getDouble( fUL
, xOpt
, rUL
);
990 fRet
= bContainsValue
? (Erf( fUL
) - Erf( fLL
)) : Erf( fLL
);
991 RETURN_FINITE( fRet
);
995 double SAL_CALL
AnalysisAddIn::getErfc( double f
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
997 double fRet
= Erfc( f
);
998 RETURN_FINITE( fRet
);
1002 sal_Int32 SAL_CALL
AnalysisAddIn::getGestep( const uno::Reference
< beans::XPropertySet
>& xOpt
, double fNum
, const uno::Any
& rStep
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1004 return fNum
>= aAnyConv
.getDouble( xOpt
, rStep
, 0.0 );
1008 double SAL_CALL
AnalysisAddIn::getFactdouble( sal_Int32 nNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1010 double fRet
= FactDouble( nNum
);
1011 RETURN_FINITE( fRet
);
1015 double SAL_CALL
AnalysisAddIn::getImabs( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1017 double fRet
= Complex( aNum
).Abs();
1018 RETURN_FINITE( fRet
);
1022 double SAL_CALL
AnalysisAddIn::getImaginary( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1024 double fRet
= Complex( aNum
).Imag();
1025 RETURN_FINITE( fRet
);
1029 OUString SAL_CALL
AnalysisAddIn::getImpower( const OUString
& aNum
, double f
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1035 return z
.GetString();
1039 double SAL_CALL
AnalysisAddIn::getImargument( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1041 double fRet
= Complex( aNum
).Arg();
1042 RETURN_FINITE( fRet
);
1046 OUString SAL_CALL
AnalysisAddIn::getImcos( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1052 return z
.GetString();
1056 OUString SAL_CALL
AnalysisAddIn::getImdiv( const OUString
& aDivid
, const OUString
& aDivis
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1058 Complex
z( aDivid
);
1060 z
.Div( Complex( aDivis
) );
1062 return z
.GetString();
1066 OUString SAL_CALL
AnalysisAddIn::getImexp( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1072 return z
.GetString();
1076 OUString SAL_CALL
AnalysisAddIn::getImconjugate( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1082 return z
.GetString();
1086 OUString SAL_CALL
AnalysisAddIn::getImln( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1092 return z
.GetString();
1096 OUString SAL_CALL
AnalysisAddIn::getImlog10( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1102 return z
.GetString();
1106 OUString SAL_CALL
AnalysisAddIn::getImlog2( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1112 return z
.GetString();
1116 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
)
1120 z_list
.Append( aNum1
, AH_IgnoreEmpty
);
1121 z_list
.Append( aNL
, AH_IgnoreEmpty
);
1123 const Complex
* p
= z_list
.First();
1126 return Complex( 0 ).GetString();
1130 for( p
= z_list
.Next() ; p
; p
= z_list
.Next() )
1133 return z
.GetString();
1137 double SAL_CALL
AnalysisAddIn::getImreal( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1139 double fRet
= Complex( aNum
).Real();
1140 RETURN_FINITE( fRet
);
1144 OUString SAL_CALL
AnalysisAddIn::getImsin( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1150 return z
.GetString();
1154 OUString SAL_CALL
AnalysisAddIn::getImsub( const OUString
& aNum1
, const OUString
& aNum2
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1158 z
.Sub( Complex( aNum2
) );
1160 return z
.GetString();
1164 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
)
1168 z_list
.Append( aNum1
, AH_IgnoreEmpty
);
1169 z_list
.Append( aFollowingPars
, AH_IgnoreEmpty
);
1171 const Complex
* p
= z_list
.First();
1174 return Complex( 0 ).GetString();
1178 for( p
= z_list
.Next() ; p
; p
= z_list
.Next() )
1181 return z
.GetString();
1185 OUString SAL_CALL
AnalysisAddIn::getImsqrt( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1191 return z
.GetString();
1195 OUString SAL_CALL
AnalysisAddIn::getImtan( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1201 return z
.GetString();
1205 OUString SAL_CALL
AnalysisAddIn::getImsec( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1211 return z
.GetString();
1215 OUString SAL_CALL
AnalysisAddIn::getImcsc( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1221 return z
.GetString();
1225 OUString SAL_CALL
AnalysisAddIn::getImcot( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1231 return z
.GetString();
1235 OUString SAL_CALL
AnalysisAddIn::getImsinh( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1241 return z
.GetString();
1245 OUString SAL_CALL
AnalysisAddIn::getImcosh( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1251 return z
.GetString();
1255 OUString SAL_CALL
AnalysisAddIn::getImsech( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1261 return z
.GetString();
1265 OUString SAL_CALL
AnalysisAddIn::getImcsch( const OUString
& aNum
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1271 return z
.GetString();
1275 OUString SAL_CALL
AnalysisAddIn::getComplex( double fR
, double fI
, const uno::Any
& rSuff
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1279 switch( rSuff
.getValueTypeClass() )
1281 case uno::TypeClass_VOID
:
1284 case uno::TypeClass_STRING
:
1286 const OUString
* pSuff
= ( const OUString
* ) rSuff
.getValue();
1287 bi
= pSuff
->compareToAscii( "i" ) == 0 || pSuff
->isEmpty();
1288 if( !bi
&& pSuff
->compareToAscii( "j" ) != 0 )
1289 throw lang::IllegalArgumentException();
1293 throw lang::IllegalArgumentException();
1296 return Complex( fR
, fI
, bi
? 'i' : 'j' ).GetString();
1300 double SAL_CALL
AnalysisAddIn::getConvert( double f
, const OUString
& aFU
, const OUString
& aTU
) throw( uno::RuntimeException
, lang::IllegalArgumentException
)
1303 pCDL
= new ConvertDataList();
1305 double fRet
= pCDL
->Convert( f
, aFU
, aTU
);
1306 RETURN_FINITE( fRet
);
1310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */