27#include <rtl/math.hxx>
36constexpr OUStringLiteral
MY_SERVICE =
u"com.sun.star.sheet.addin.Analysis";
37constexpr OUStringLiteral
MY_IMPLNAME =
u"com.sun.star.sheet.addin.AnalysisImpl";
68 const uno::Reference< beans::XPropertySet >& xPropSet,
72 if( (nMode < 0) || (nMode > 4) )
73 throw lang::IllegalArgumentException();
77#define MAXFACTDOUBLE 300
82 throw lang::IllegalArgumentException();
169 if( it !=
pFD->end() )
174 const OUString& rSuffix = it->GetSuffix();
175 if (!rSuffix.isEmpty())
183 aRet =
"UNKNOWNFUNC_" + aProgrammaticName;
194 if( it !=
pFD->end() )
205 if( it !=
pFD->end() && nArg <= 0xFFFF )
207 sal_uInt16 nStr = it->GetStrIndex( sal_uInt16( nArg ) );
222 if( it !=
pFD->end() && nArg <= 0xFFFF )
224 sal_uInt16 nStr = it->GetStrIndex( sal_uInt16( nArg ) );
228 aRet =
"for internal use only";
242 if( it !=
pFD->end() )
244 switch( it->GetCategory() )
246 case FDCategory::DateTime: aRet =
"Date&Time";
break;
247 case FDCategory::Finance: aRet =
"Financial";
break;
248 case FDCategory::Inf: aRet =
"Information";
break;
249 case FDCategory::Math: aRet =
"Mathematical";
break;
250 case FDCategory::Tech: aRet =
"Technical";
break;
262 auto it = std::find_if(
pFD->begin(),
pFD->end(),
FindFuncData( aProgrammaticFunctionName ) );
264 if( it !=
pFD->end() )
266 switch( it->GetCategory() )
268 case FDCategory::DateTime: aRet =
"Date&Time";
break;
269 case FDCategory::Finance: aRet =
"Financial";
break;
270 case FDCategory::Inf: aRet =
"Information";
break;
271 case FDCategory::Math: aRet =
"Mathematical";
break;
272 case FDCategory::Tech: aRet =
"Technical";
break;
281static const char*
pLang[] = {
"de",
"en" };
282static const char*
pCoun[] = {
"DE",
"US" };
310 if( it ==
pFD->end() )
311 return uno::Sequence< sheet::LocalizedName >( 0 );
313 const std::vector<OUString>& r = it->GetCompNameList();
314 sal_uInt32
nCount = r.size();
316 uno::Sequence< sheet::LocalizedName > aRet(
nCount );
318 sheet::LocalizedName* pArray = aRet.getArray();
320 for( sal_uInt32
n = 0 ;
n <
nCount ;
n++ )
322 pArray[
n ] = sheet::LocalizedName(
GetLocale(
n ), r[
n] );
331 sal_Int32 nDate, sal_Int32 nDays,
const uno::Any& aHDay )
342 sal_Int32 nActDate = nDate + nNullDate;
356 if( !aSrtLst.
Find( nActDate ) )
375 if( !aSrtLst.
Find( nActDate ) )
383 return nActDate - nNullDate;
388 sal_Int32 nStartDate, sal_Int32 nEndDate,
const uno::Any& rMode )
394sal_Int32 SAL_CALL
AnalysisAddIn::getEdate(
const uno::Reference< beans::XPropertySet >& xOpt, sal_Int32 nStartDate, sal_Int32 nMonths )
397 ScaDate aDate( nNullDate, nStartDate, 5 );
399 return aDate.
getDate( nNullDate );
406 sal_uInt16 nDay, nMonth, nYear;
409 sal_Int32 nFirstInYear =
DateToDays( 1, 1, nYear );
410 sal_uInt16 nFirstDayInYear =
GetDayOfWeek( nFirstInYear );
412 return ( nDate - nFirstInYear + ( ( nMode == 1 )? ( nFirstDayInYear + 1 ) % 7 : nFirstDayInYear ) ) / 7 + 1;
419 sal_uInt16 nDay, nMonth, nYear;
422 sal_Int32 nNewMonth = nMonth + nMonths;
426 nYear = sal::static_int_cast<sal_uInt16>( nYear + ( nNewMonth / 12 ) );
429 else if( nNewMonth < 1 )
431 nNewMonth = -nNewMonth;
432 nYear = sal::static_int_cast<sal_uInt16>( nYear - ( nNewMonth / 12 ) );
435 nNewMonth = 12 - nNewMonth;
438 return DateToDays(
DaysInMonth( sal_uInt16( nNewMonth ), nYear ), sal_uInt16( nNewMonth ), nYear ) - nNullDate;
442 sal_Int32 nStartDate, sal_Int32 nEndDate,
const uno::Any& aHDay )
450 sal_Int32 nActDate = nStartDate + nNullDate;
451 sal_Int32 nStopDate = nEndDate + nNullDate;
454 if( nActDate <= nStopDate )
456 while( nActDate <= nStopDate )
466 while( nActDate >= nStopDate )
480 return ( nVal & 0x00000001 )? 0 : 1;
485 return ( nVal & 0x00000001 )? 1 : 0;
490 const uno::Sequence< uno::Any >& aOptVLst )
497 if( aValList.
Count() == 0 )
503 for( sal_uInt32
i = 0;
i < aValList.
Count(); ++
i )
505 const double d = aValList.
Get(
i);
506 double n = (
d >= 0.0) ? rtl::math::approxFloor(
d ) : rtl::math::approxCeil(
d );
508 throw lang::IllegalArgumentException();
524 if( fX == 0.0 && fN == 0 )
525 throw uno::RuntimeException(
"undefined expression: 0^0");
529 for(
const uno::Sequence< double >& rList : aCoeffList )
531 for(
const double fCoef : rList )
533 fRet += fCoef * pow( fX, fN );
546 if( (fNum < 0) != (fDenom < 0) )
547 fRet = ::rtl::math::approxCeil( fNum / fDenom );
549 fRet = ::rtl::math::approxFloor( fNum / fDenom );
558 double fRet = fMult * ::rtl::math::round( ::rtl::math::approxValue( fNum / fMult));
564 double fRet = sqrt( fNum * M_PI );
570 fMin = ::rtl::math::round( fMin, 0, rtl_math_RoundingMode_Up );
571 fMax = ::rtl::math::round( fMax, 0, rtl_math_RoundingMode_Up );
573 throw lang::IllegalArgumentException();
579double SAL_CALL
AnalysisAddIn::getGcd(
const uno::Reference< beans::XPropertySet >& xOpt,
const uno::Sequence< uno::Sequence< double > >& aVLst,
const uno::Sequence< uno::Any >& aOptVLst )
586 if( aValList.
Count() == 0 )
589 double f = aValList.
Get(0);
590 for( sal_uInt32
i = 1;
i < aValList.
Count(); ++
i )
598double SAL_CALL
AnalysisAddIn::getLcm(
const uno::Reference< beans::XPropertySet >& xOpt,
const uno::Sequence< uno::Sequence< double > >& aVLst,
const uno::Sequence< uno::Any >& aOptVLst )
605 if( aValList.
Count() == 0 )
608 double f = rtl::math::approxFloor( aValList.
Get(0) );
610 throw lang::IllegalArgumentException();
615 for( sal_uInt32
i = 1;
i < aValList.
Count(); ++
i )
617 double fTmp = rtl::math::approxFloor( aValList.
Get(
i) );
619 throw lang::IllegalArgumentException();
621 f = fTmp * f /
GetGcd( fTmp, f );
643 if( nOrder < 0 || fNum <= 0.0 )
644 throw lang::IllegalArgumentException();
652 if( nOrder < 0 || fNum <= 0.0 )
653 throw lang::IllegalArgumentException();
670 sal_Int32 nPlaces = 0;
684 sal_Int32 nPlaces = 0;
692 sal_Int32 nPlaces = 0;
706 sal_Int32 nPlaces = 0;
713 sal_Int32 nPlaces = 0;
720 sal_Int32 nPlaces = 0;
727 sal_Int32 nPlaces = 0;
735 sal_Int32 nPlaces = 0;
749 sal_Int32 nPlaces = 0;
764 fRet = bContainsValue ? (
Erf( fUL ) -
Erf( fLL )) :
Erf( fLL );
770 double fRet =
Erfc( f );
803 return z.GetString();
818 return z.GetString();
827 return z.GetString();
836 return z.GetString();
845 return z.GetString();
854 return z.GetString();
863 return z.GetString();
872 return z.GetString();
875OUString SAL_CALL
AnalysisAddIn::getImproduct(
const uno::Reference< beans::XPropertySet >&,
const uno::Sequence< uno::Sequence< OUString > >& aNum1,
const uno::Sequence< uno::Any >& aNL )
886 for( sal_uInt32
i = 1;
i < z_list.
Count(); ++
i )
887 z.Mult( z_list.
Get(
i) );
889 return z.GetString();
904 return z.GetString();
913 return z.GetString();
916OUString SAL_CALL
AnalysisAddIn::getImsum(
const uno::Reference< beans::XPropertySet >&,
const uno::Sequence< uno::Sequence< OUString > >& aNum1,
const uno::Sequence< uno::Any >& aFollowingPars )
921 z_list.
Append( aFollowingPars );
927 for( sal_uInt32
i = 1;
i < z_list.
Count(); ++
i )
928 z.Add( z_list.
Get(
i) );
930 return z.GetString();
939 return z.GetString();
948 return z.GetString();
957 return z.GetString();
966 return z.GetString();
975 return z.GetString();
984 return z.GetString();
993 return z.GetString();
1002 return z.GetString();
1011 return z.GetString();
1018 switch( rSuff.getValueTypeClass() )
1020 case uno::TypeClass_VOID:
1023 case uno::TypeClass_STRING:
1025 auto pSuff = o3tl::forceAccess<OUString>(rSuff);
1026 bi = *pSuff ==
"i" || pSuff->isEmpty();
1027 if( !bi && *pSuff !=
"j" )
1028 throw lang::IllegalArgumentException();
1032 throw lang::IllegalArgumentException();
1043 double fRet =
pCDL->Convert( f, aFU, aTU );
1052extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1054 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
static const char * pCoun[]
const sal_uInt32 nNumOfLoc
constexpr OUStringLiteral MY_IMPLNAME
const sal_Int32 SCA_MAXPLACES
static const char * pLang[]
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * scaddins_AnalysisAddIn_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral pDefCatName
constexpr OUStringLiteral ADDIN_SERVICE
constexpr OUStringLiteral MY_SERVICE
cppu::WeakComponentImplHelper< css::sheet::XAddIn, css::sheet::XCompatibilityNames, css::sheet::addin::XAnalysis, css::lang::XServiceName, css::lang::XServiceInfo > AnalysisAddIn_Base
double finiteOrThrow(double d)
std::unique_ptr< sca::analysis::ConvertDataList > pCDL
virtual OUString SAL_CALL getImexp(const OUString &aNum) override
virtual double SAL_CALL getMultinomial(const css::uno::Reference< css::beans::XPropertySet > &xOpt, const css::uno::Sequence< css::uno::Sequence< sal_Int32 > > &aVLst, const css::uno::Sequence< css::uno::Any > &aOptVLst) override
virtual double SAL_CALL getQuotient(double fNum, double fDenum) override
virtual OUString SAL_CALL getImlog10(const OUString &aNum) override
virtual OUString SAL_CALL getDisplayCategoryName(const OUString &aProgrammaticFunctionName) override
virtual OUString SAL_CALL getOct2Hex(const css::uno::Reference< css::beans::XPropertySet > &xOpt, const OUString &aNum, const css::uno::Any &rPlaces) override
virtual OUString SAL_CALL getImsec(const OUString &aNum) override
virtual OUString SAL_CALL getImcsc(const OUString &aNum) override
virtual OUString SAL_CALL getDisplayFunctionName(const OUString &aProgrammaticName) override
css::lang::Locale aFuncLoc
virtual double SAL_CALL getImabs(const OUString &aNum) override
virtual double SAL_CALL getSqrtpi(double fNum) override
virtual OUString SAL_CALL getDec2Hex(const css::uno::Reference< css::beans::XPropertySet > &xOpt, double fNum, const css::uno::Any &rPlaces) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual double SAL_CALL getBesseli(double fNum, sal_Int32 nOrder) override
virtual OUString SAL_CALL getBin2Oct(const css::uno::Reference< css::beans::XPropertySet > &xOpt, const OUString &aNum, const css::uno::Any &rPlaces) override
virtual OUString SAL_CALL getImsum(const css::uno::Reference< css::beans::XPropertySet > &xOpt, const css::uno::Sequence< css::uno::Sequence< OUString > > &aNum1, const css::uno::Sequence< css::uno::Any > &aFollowingPars) override
virtual OUString SAL_CALL getServiceName() override
virtual sal_Int32 SAL_CALL getNetworkdays(const css::uno::Reference< css::beans::XPropertySet > &, sal_Int32 nStartDate, sal_Int32 nEndDate, const css::uno::Any &aHDay) override
virtual OUString SAL_CALL getImln(const OUString &aNum) override
virtual sal_Int32 SAL_CALL getEomonth(const css::uno::Reference< css::beans::XPropertySet > &, sal_Int32 nStartDate, sal_Int32 nMonths) override
virtual OUString SAL_CALL getProgrammaticCategoryName(const OUString &aProgrammaticFunctionName) override
std::unique_ptr< css::lang::Locale[]> pDefLocales
virtual sal_Int32 SAL_CALL getGestep(const css::uno::Reference< css::beans::XPropertySet > &xOpt, double fNum, const css::uno::Any &rStep) override
virtual double SAL_CALL getRandbetween(double fMin, double fMax) override
virtual OUString SAL_CALL getImcosh(const OUString &aNum) override
virtual sal_Int32 SAL_CALL getIsodd(sal_Int32 nVal) override
virtual OUString SAL_CALL getFunctionDescription(const OUString &aProgrammaticName) override
virtual OUString SAL_CALL getImsech(const OUString &aNum) override
virtual css::lang::Locale SAL_CALL getLocale() override
virtual OUString SAL_CALL getDisplayArgumentName(const OUString &aProgrammaticFunctionName, sal_Int32 nArgument) override
virtual OUString SAL_CALL getImsin(const OUString &aNum) override
virtual OUString SAL_CALL getImlog2(const OUString &aNum) override
virtual OUString SAL_CALL getDec2Bin(const css::uno::Reference< css::beans::XPropertySet > &xOpt, sal_Int32 fNum, const css::uno::Any &rPlaces) override
virtual OUString SAL_CALL getImsinh(const OUString &aNum) override
virtual double SAL_CALL getErfc(double fLowerLimit) override
virtual OUString SAL_CALL getHex2Bin(const css::uno::Reference< css::beans::XPropertySet > &xOpt, const OUString &aNum, const css::uno::Any &rPlaces) override
virtual double SAL_CALL getImaginary(const OUString &aNum) override
virtual double SAL_CALL getSeriessum(double fX, double fN, double fM, const css::uno::Sequence< css::uno::Sequence< double > > &aCoeffList) override
virtual OUString SAL_CALL getImcos(const OUString &aNum) override
virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames(const OUString &aProgrammaticName) override
virtual OUString SAL_CALL getBin2Hex(const css::uno::Reference< css::beans::XPropertySet > &xOpt, const OUString &aNum, const css::uno::Any &rPlaces) override
virtual OUString SAL_CALL getDec2Oct(const css::uno::Reference< css::beans::XPropertySet > &xOpt, sal_Int32 fNum, const css::uno::Any &rPlaces) override
virtual double SAL_CALL getOct2Dec(const OUString &aNum) override
std::unique_ptr< sca::analysis::FuncDataList > pFD
virtual OUString SAL_CALL getImplementationName() override
OUString GetFuncDescrStr(const TranslateId *pResId, sal_uInt16 nStrIndex)
virtual OUString SAL_CALL getImproduct(const css::uno::Reference< css::beans::XPropertySet > &xOpt, const css::uno::Sequence< css::uno::Sequence< OUString > > &aNum1, const css::uno::Sequence< css::uno::Any > &aNumList) override
const css::lang::Locale & GetLocale(sal_uInt32 nInd)
virtual void SAL_CALL setLocale(const css::lang::Locale &eLocale) override
virtual OUString SAL_CALL getImsub(const OUString &aNum1, const OUString &aNum2) override
virtual OUString SAL_CALL getImpower(const OUString &aNum, double fPower) override
virtual OUString SAL_CALL getImdiv(const OUString &aDivident, const OUString &aDivisor) override
OUString AnalysisResId(TranslateId aId)
virtual OUString SAL_CALL getOct2Bin(const css::uno::Reference< css::beans::XPropertySet > &xOpt, const OUString &aNum, const css::uno::Any &rPlaces) override
virtual double SAL_CALL getImreal(const OUString &aNum) override
virtual OUString SAL_CALL getImconjugate(const OUString &aNum) override
virtual double SAL_CALL getConvert(double fVal, const OUString &aFromUnit, const OUString &aToUnit) override
virtual OUString SAL_CALL getImcot(const OUString &aNum) override
virtual OUString SAL_CALL getComplex(double fReal, double fImaginary, const css::uno::Any &rSuffix) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getArgumentDescription(const OUString &aProgrammaticFunctionName, sal_Int32 nArgument) override
virtual OUString SAL_CALL getImsqrt(const OUString &aNum) override
virtual OUString SAL_CALL getProgrammaticFuntionName(const OUString &aDisplayName) override
virtual OUString SAL_CALL getHex2Oct(const css::uno::Reference< css::beans::XPropertySet > &xOpt, const OUString &aNum, const css::uno::Any &rPlaces) override
double FactDouble(sal_Int32 nNum)
virtual double SAL_CALL getBesselj(double fNum, sal_Int32 nOrder) override
virtual sal_Int32 SAL_CALL getWorkday(const css::uno::Reference< css::beans::XPropertySet > &, sal_Int32 nStartDate, sal_Int32 nDays, const css::uno::Any &aHDay) override
Workday.
virtual sal_Int32 SAL_CALL getWeeknum(const css::uno::Reference< css::beans::XPropertySet > &, sal_Int32 nStartDate, sal_Int32 nMode) override
virtual double SAL_CALL getErf(const css::uno::Reference< css::beans::XPropertySet > &xOpt, double fLowerLimit, const css::uno::Any &rUpperLimit) override
virtual double SAL_CALL getHex2Dec(const OUString &aNum) override
virtual double SAL_CALL getFactdouble(sal_Int32 nNum) override
virtual double SAL_CALL getGcd(const css::uno::Reference< css::beans::XPropertySet > &xOpt, const css::uno::Sequence< css::uno::Sequence< double > > &aVLst, const css::uno::Sequence< css::uno::Any > &aOptVLst) override
virtual sal_Int32 SAL_CALL getDelta(const css::uno::Reference< css::beans::XPropertySet > &xOpt, double fNum1, const css::uno::Any &rNum2) override
virtual double SAL_CALL getBessely(double fNum, sal_Int32 nOrder) override
virtual sal_Int32 SAL_CALL getEdate(const css::uno::Reference< css::beans::XPropertySet > &, sal_Int32 nStartDate, sal_Int32 nMonths) override
virtual double SAL_CALL getImargument(const OUString &aNum) override
virtual double SAL_CALL getLcm(const css::uno::Reference< css::beans::XPropertySet > &xOpt, const css::uno::Sequence< css::uno::Sequence< double > > &aVLst, const css::uno::Sequence< css::uno::Any > &aOptVLst) override
virtual double SAL_CALL getBesselk(double fNum, sal_Int32 nOrder) override
sca::analysis::ScaAnyConverter aAnyConv
virtual sal_Int32 SAL_CALL getIseven(sal_Int32 nVal) override
virtual ~AnalysisAddIn() override
sal_Int32 getDateMode(const css::uno::Reference< css::beans::XPropertySet > &xPropSet, const css::uno::Any &rAny)
Converts an Any to sal_Int32 in the range from 0 to 4 (date calculation mode).
virtual double SAL_CALL getMround(double fNum, double fMult) override
virtual OUString SAL_CALL getImtan(const OUString &aNum) override
virtual double SAL_CALL getYearfrac(const css::uno::Reference< css::beans::XPropertySet > &, sal_Int32 nStartDate, sal_Int32 nEndDate, const css::uno::Any &aMode) override
Yearfrac.
virtual double SAL_CALL getBin2Dec(const OUString &aNum) override
virtual OUString SAL_CALL getImcsch(const OUString &aNum) override
AnalysisAddIn(const css::uno::Reference< css::uno::XComponentContext > &xContext)
std::unique_ptr< double[]> pFactDoubles
void Append(Complex &&pNew)
const Complex & Get(sal_uInt32 nIndex) const
OUString GetString() const
bool getDouble(double &rfResult, const css::uno::Any &rAny) const
Converts an Any to double (without initialization).
bool getInt32(sal_Int32 &rnResult, const css::uno::Reference< css::beans::XPropertySet > &xPropSet, const css::uno::Any &rAny)
Converts an Any to sal_Int32 (with initialization).
Helper class for date calculation for various financial functions.
sal_Int32 getDate(sal_Int32 nNullDate) const
void addMonths(sal_Int32 nMonthCount)
adds/subtracts the given count of months, adjusts day
stores double values >=0.0, throws exception for double values <0.0
stores double values >0.0, throws exception for double values <0.0, does nothing for 0....
double Get(sal_uInt32 n) const
void Append(double fValue)
sorted list with unique sal_Int32 values
bool Find(sal_Int32 nVal) const
void InsertHolidayList(const ScaAnyConverter &rAnyConv, const css::uno::Any &rHolAny, sal_Int32 nNullDate, bool bInsertOnWeekend)
#define SAL_N_ELEMENTS(arr)
std::locale Create(std::string_view aPrefixName, const LanguageTag &rLocale)
OUString get(TranslateId sContextAndId, const std::locale &loc)
double uniform_real_distribution(double a=0.0, double b=1.0)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
double BinomialCoefficient(double n, double k)
void InitFuncDataList(FuncDataList &rList)
double BesselI(double x, sal_Int32 n)
Returns the result for the modified BESSEL function of first kind (I), n-th order,...
double GetGcd(double f1, double f2)
double BesselK(double fNum, sal_Int32 nOrder)
Returns the result for the modified BESSEL function of second kind (K), n-th order,...
OUString ConvertFromDec(double fNum, double fMin, double fMax, sal_uInt16 nBase, sal_Int32 nPlaces, sal_Int32 nMaxPlaces, bool bUsePlaces)
double ConvertToDec(const OUString &aStr, sal_uInt16 nBase, sal_uInt16 nCharLim)
double BesselY(double fNum, sal_Int32 nOrder)
Returns the result for the unmodified BESSEL function of second kind (Y), n-th order,...
double BesselJ(double x, sal_Int32 N)
Returns the result for the unmodified BESSEL function of first kind (J), n-th order,...
sal_Int16 GetDayOfWeek(sal_Int32 nDate)
std::vector< FuncData > FuncDataList