Drop some defines in scaddins
Change-Id: I6155ad1c9e4627aad65ae1884e03491902c5d8a6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150780 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
@@ -388,7 +388,7 @@ double SAL_CALL AnalysisAddIn::getYearfrac( const uno::Reference< beans::XProper
|
||||
sal_Int32 nStartDate, sal_Int32 nEndDate, const uno::Any& rMode )
|
||||
{
|
||||
double fRet = GetYearFrac( xOpt, nStartDate, nEndDate, getDateMode( xOpt, rMode ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
sal_Int32 SAL_CALL AnalysisAddIn::getEdate( const uno::Reference< beans::XPropertySet >& xOpt, sal_Int32 nStartDate, sal_Int32 nMonths )
|
||||
@@ -513,7 +513,7 @@ AnalysisAddIn::getMultinomial( const uno::Reference< beans::XPropertySet >& xOpt
|
||||
fRet *= BinomialCoefficient(nZ, n);
|
||||
}
|
||||
}
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getSeriessum( double fX, double fN, double fM, const uno::Sequence< uno::Sequence< double > >& aCoeffList )
|
||||
@@ -537,7 +537,7 @@ double SAL_CALL AnalysisAddIn::getSeriessum( double fX, double fN, double fM, co
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getQuotient( double fNum, double fDenom )
|
||||
@@ -547,7 +547,7 @@ double SAL_CALL AnalysisAddIn::getQuotient( double fNum, double fDenom )
|
||||
fRet = ::rtl::math::approxCeil( fNum / fDenom );
|
||||
else
|
||||
fRet = ::rtl::math::approxFloor( fNum / fDenom );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getMround( double fNum, double fMult )
|
||||
@@ -556,13 +556,13 @@ double SAL_CALL AnalysisAddIn::getMround( double fNum, double fMult )
|
||||
return fMult;
|
||||
|
||||
double fRet = fMult * ::rtl::math::round( ::rtl::math::approxValue( fNum / fMult));
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getSqrtpi( double fNum )
|
||||
{
|
||||
double fRet = sqrt( fNum * M_PI );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getRandbetween( double fMin, double fMax )
|
||||
@@ -573,7 +573,7 @@ double SAL_CALL AnalysisAddIn::getRandbetween( double fMin, double fMax )
|
||||
throw lang::IllegalArgumentException();
|
||||
|
||||
double fRet = floor(comphelper::rng::uniform_real_distribution(fMin, nextafter(fMax+1, -DBL_MAX)));
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getGcd( const uno::Reference< beans::XPropertySet >& xOpt, const uno::Sequence< uno::Sequence< double > >& aVLst, const uno::Sequence< uno::Any >& aOptVLst )
|
||||
@@ -592,7 +592,7 @@ double SAL_CALL AnalysisAddIn::getGcd( const uno::Reference< beans::XPropertySet
|
||||
f = GetGcd( aValList.Get(i), f );
|
||||
}
|
||||
|
||||
RETURN_FINITE( f );
|
||||
return finiteOrThrow( f );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getLcm( const uno::Reference< beans::XPropertySet >& xOpt, const uno::Sequence< uno::Sequence< double > >& aVLst, const uno::Sequence< uno::Any >& aOptVLst )
|
||||
@@ -623,19 +623,19 @@ double SAL_CALL AnalysisAddIn::getLcm( const uno::Reference< beans::XPropertySet
|
||||
return f;
|
||||
}
|
||||
|
||||
RETURN_FINITE( f );
|
||||
return finiteOrThrow( f );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getBesseli( double fNum, sal_Int32 nOrder )
|
||||
{
|
||||
double fRet = sca::analysis::BesselI( fNum, nOrder );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getBesselj( double fNum, sal_Int32 nOrder )
|
||||
{
|
||||
double fRet = sca::analysis::BesselJ( fNum, nOrder );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getBesselk( double fNum, sal_Int32 nOrder )
|
||||
@@ -644,7 +644,7 @@ double SAL_CALL AnalysisAddIn::getBesselk( double fNum, sal_Int32 nOrder )
|
||||
throw lang::IllegalArgumentException();
|
||||
|
||||
double fRet = sca::analysis::BesselK( fNum, nOrder );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getBessely( double fNum, sal_Int32 nOrder )
|
||||
@@ -653,7 +653,7 @@ double SAL_CALL AnalysisAddIn::getBessely( double fNum, sal_Int32 nOrder )
|
||||
throw lang::IllegalArgumentException();
|
||||
|
||||
double fRet = sca::analysis::BesselY( fNum, nOrder );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
const double SCA_MAX2 = 511.0; // min. val for binary numbers (9 bits + sign)
|
||||
@@ -675,7 +675,7 @@ OUString SAL_CALL AnalysisAddIn::getBin2Oct( const uno::Reference< beans::XPrope
|
||||
double SAL_CALL AnalysisAddIn::getBin2Dec( const OUString& aNum )
|
||||
{
|
||||
double fRet = ConvertToDec( aNum, 2, SCA_MAXPLACES );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
OUString SAL_CALL AnalysisAddIn::getBin2Hex( const uno::Reference< beans::XPropertySet >& xOpt, const OUString& aNum, const uno::Any& rPlaces )
|
||||
@@ -697,7 +697,7 @@ OUString SAL_CALL AnalysisAddIn::getOct2Bin( const uno::Reference< beans::XPrope
|
||||
double SAL_CALL AnalysisAddIn::getOct2Dec( const OUString& aNum )
|
||||
{
|
||||
double fRet = ConvertToDec( aNum, 8, SCA_MAXPLACES );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
OUString SAL_CALL AnalysisAddIn::getOct2Hex( const uno::Reference< beans::XPropertySet >& xOpt, const OUString& aNum, const uno::Any& rPlaces )
|
||||
@@ -740,7 +740,7 @@ OUString SAL_CALL AnalysisAddIn::getHex2Bin( const uno::Reference< beans::XPrope
|
||||
double SAL_CALL AnalysisAddIn::getHex2Dec( const OUString& aNum )
|
||||
{
|
||||
double fRet = ConvertToDec( aNum, 16, SCA_MAXPLACES );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
OUString SAL_CALL AnalysisAddIn::getHex2Oct( const uno::Reference< beans::XPropertySet >& xOpt, const OUString& aNum, const uno::Any& rPlaces )
|
||||
@@ -762,13 +762,13 @@ double SAL_CALL AnalysisAddIn::getErf( const uno::Reference< beans::XPropertySet
|
||||
bool bContainsValue = aAnyConv.getDouble( fUL, xOpt, rUL );
|
||||
|
||||
fRet = bContainsValue ? (Erf( fUL ) - Erf( fLL )) : Erf( fLL );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getErfc( double f )
|
||||
{
|
||||
double fRet = Erfc( f );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
sal_Int32 SAL_CALL AnalysisAddIn::getGestep( const uno::Reference< beans::XPropertySet >& xOpt, double fNum, const uno::Any& rStep )
|
||||
@@ -779,19 +779,19 @@ sal_Int32 SAL_CALL AnalysisAddIn::getGestep( const uno::Reference< beans::XPrope
|
||||
double SAL_CALL AnalysisAddIn::getFactdouble( sal_Int32 nNum )
|
||||
{
|
||||
double fRet = FactDouble( nNum );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getImabs( const OUString& aNum )
|
||||
{
|
||||
double fRet = Complex( aNum ).Abs();
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getImaginary( const OUString& aNum )
|
||||
{
|
||||
double fRet = Complex( aNum ).Imag();
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
OUString SAL_CALL AnalysisAddIn::getImpower( const OUString& aNum, double f )
|
||||
@@ -806,7 +806,7 @@ OUString SAL_CALL AnalysisAddIn::getImpower( const OUString& aNum, double f )
|
||||
double SAL_CALL AnalysisAddIn::getImargument( const OUString& aNum )
|
||||
{
|
||||
double fRet = Complex( aNum ).Arg();
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
OUString SAL_CALL AnalysisAddIn::getImcos( const OUString& aNum )
|
||||
@@ -892,7 +892,7 @@ OUString SAL_CALL AnalysisAddIn::getImproduct( const uno::Reference< beans::XPro
|
||||
double SAL_CALL AnalysisAddIn::getImreal( const OUString& aNum )
|
||||
{
|
||||
double fRet = Complex( aNum ).Real();
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
OUString SAL_CALL AnalysisAddIn::getImsin( const OUString& aNum )
|
||||
@@ -1041,7 +1041,7 @@ double SAL_CALL AnalysisAddIn::getConvert( double f, const OUString& aFU, const
|
||||
pCDL.reset(new ConvertDataList());
|
||||
|
||||
double fRet = pCDL->Convert( f, aFU, aTU );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
OUString AnalysisAddIn::AnalysisResId(TranslateId aResId)
|
||||
|
||||
@@ -22,8 +22,12 @@
|
||||
#include <com/sun/star/lang/IllegalArgumentException.hpp>
|
||||
#include <cmath>
|
||||
|
||||
#define CHK_Freq ( nFreq != 1 && nFreq != 2 && nFreq != 4 )
|
||||
#define CHK_FINITE(d) if( !std::isfinite( d ) ) throw css::lang::IllegalArgumentException()
|
||||
#define RETURN_FINITE(d) if( !std::isfinite( d ) ) throw css::lang::IllegalArgumentException(); return d;
|
||||
inline bool isFreqInvalid(sal_Int32 nFreq) { return nFreq != 1 && nFreq != 2 && nFreq != 4; }
|
||||
inline double finiteOrThrow(double d)
|
||||
{
|
||||
if (!std::isfinite(d))
|
||||
throw css::lang::IllegalArgumentException();
|
||||
return d;
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -1249,7 +1249,7 @@ static void lcl_GetCouppcd( ScaDate& rDate, const ScaDate& rSettle, const ScaDat
|
||||
|
||||
double GetCouppcd( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase )
|
||||
{
|
||||
if( nSettle >= nMat || CHK_Freq )
|
||||
if( nSettle >= nMat || isFreqInvalid(nFreq) )
|
||||
throw lang::IllegalArgumentException();
|
||||
|
||||
ScaDate aDate;
|
||||
@@ -1271,7 +1271,7 @@ static void lcl_GetCoupncd( ScaDate& rDate, const ScaDate& rSettle, const ScaDat
|
||||
|
||||
double GetCoupncd( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase )
|
||||
{
|
||||
if( nSettle >= nMat || CHK_Freq )
|
||||
if( nSettle >= nMat || isFreqInvalid(nFreq) )
|
||||
throw lang::IllegalArgumentException();
|
||||
|
||||
ScaDate aDate;
|
||||
@@ -1282,7 +1282,7 @@ double GetCoupncd( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_I
|
||||
// COUPDAYBS: get day count: coupon date before settlement <-> settlement
|
||||
double GetCoupdaybs( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase )
|
||||
{
|
||||
if( nSettle >= nMat || CHK_Freq )
|
||||
if( nSettle >= nMat || isFreqInvalid(nFreq) )
|
||||
throw lang::IllegalArgumentException();
|
||||
|
||||
ScaDate aSettle( nNullDate, nSettle, nBase );
|
||||
@@ -1294,7 +1294,7 @@ double GetCoupdaybs( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal
|
||||
// COUPDAYSNC: get day count: settlement <-> coupon date after settlement
|
||||
double GetCoupdaysnc( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase )
|
||||
{
|
||||
if( nSettle >= nMat || CHK_Freq )
|
||||
if( nSettle >= nMat || isFreqInvalid(nFreq) )
|
||||
throw lang::IllegalArgumentException();
|
||||
|
||||
if( (nBase != 0) && (nBase != 4) )
|
||||
@@ -1310,7 +1310,7 @@ double GetCoupdaysnc( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sa
|
||||
// COUPDAYS: get day count: coupon date before settlement <-> coupon date after settlement
|
||||
double GetCoupdays( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase )
|
||||
{
|
||||
if( nSettle >= nMat || CHK_Freq )
|
||||
if( nSettle >= nMat || isFreqInvalid(nFreq) )
|
||||
throw lang::IllegalArgumentException();
|
||||
|
||||
if( nBase == 1 )
|
||||
@@ -1327,7 +1327,7 @@ double GetCoupdays( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_
|
||||
// COUPNUM: get count of coupon dates
|
||||
double GetCoupnum( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase )
|
||||
{
|
||||
if( nSettle >= nMat || CHK_Freq )
|
||||
if( nSettle >= nMat || isFreqInvalid(nFreq) )
|
||||
throw lang::IllegalArgumentException();
|
||||
|
||||
ScaDate aMat( nNullDate, nMat, nBase );
|
||||
@@ -1652,8 +1652,8 @@ bool Complex::ParseString( const OUString& rStr, Complex& rCompl )
|
||||
|
||||
OUString Complex::GetString() const
|
||||
{
|
||||
CHK_FINITE(r);
|
||||
CHK_FINITE(i);
|
||||
finiteOrThrow(r);
|
||||
finiteOrThrow(i);
|
||||
OUStringBuffer aRet;
|
||||
|
||||
bool bHasImag = i != 0.0;
|
||||
|
||||
@@ -33,7 +33,7 @@ double SAL_CALL AnalysisAddIn::getAmordegrc( const css::uno::Reference< css::bea
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = GetAmordegrc( GetNullDate( xOpt ), fCost, nDate, nFirstPer, fRestVal, fPer, fRate, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ double SAL_CALL AnalysisAddIn::getAmorlinc( const css::uno::Reference< css::bean
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = GetAmorlinc( GetNullDate( xOpt ), fCost, nDate, nFirstPer, fRestVal, fPer, fRate, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -56,11 +56,11 @@ double SAL_CALL AnalysisAddIn::getAccrint( const css::uno::Reference< css::beans
|
||||
{
|
||||
double fVal = aAnyConv.getDouble( xOpt, rVal, 1000.0 );
|
||||
|
||||
if( fRate <= 0.0 || fVal <= 0.0 || CHK_Freq || nIssue >= nSettle )
|
||||
if( fRate <= 0.0 || fVal <= 0.0 || isFreqInvalid(nFreq) || nIssue >= nSettle)
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = fVal * fRate * GetYearDiff( GetNullDate( xOpt ), nIssue, nSettle, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ double SAL_CALL AnalysisAddIn::getAccrintm( const css::uno::Reference< css::bean
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = fVal * fRate * GetYearDiff( GetNullDate( xOpt ), nIssue, nSettle, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ double SAL_CALL AnalysisAddIn::getReceived( const css::uno::Reference< css::bean
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = fInvest / ( 1.0 - ( fDisc * GetYearDiff( GetNullDate( xOpt ), nSettle, nMat, getDateMode( xOpt, rOB ) ) ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -94,18 +94,18 @@ double SAL_CALL AnalysisAddIn::getDisc( const css::uno::Reference< css::beans::X
|
||||
if( fPrice <= 0.0 || fRedemp <= 0.0 || nSettle >= nMat )
|
||||
throw css::lang::IllegalArgumentException();
|
||||
double fRet = ( 1.0 - fPrice / fRedemp ) / GetYearFrac( xOpt, nSettle, nMat, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getDuration( const css::uno::Reference< css::beans::XPropertySet >& xOpt,
|
||||
sal_Int32 nSettle, sal_Int32 nMat, double fCoup, double fYield, sal_Int32 nFreq, const css::uno::Any& rOB )
|
||||
{
|
||||
if( fCoup < 0.0 || fYield < 0.0 || CHK_Freq || nSettle >= nMat )
|
||||
if( fCoup < 0.0 || fYield < 0.0 || isFreqInvalid(nFreq) || nSettle >= nMat )
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = GetDuration( GetNullDate( xOpt ), nSettle, nMat, fCoup, fYield, nFreq, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ double SAL_CALL AnalysisAddIn::getEffect( double fNominal, sal_Int32 nPeriods )
|
||||
double fPeriods = nPeriods;
|
||||
|
||||
double fRet = pow( 1.0 + fNominal / fPeriods, fPeriods ) - 1.0;
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ double SAL_CALL AnalysisAddIn::getCumprinc( double fRate, sal_Int32 nNumPeriods,
|
||||
fPpmt += fPmt - GetFv( fRate, double( i - 1 ), fPmt, fVal, 0 ) * fRate;
|
||||
}
|
||||
|
||||
RETURN_FINITE( fPpmt );
|
||||
return finiteOrThrow( fPpmt );
|
||||
}
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ double SAL_CALL AnalysisAddIn::getCumipmt( double fRate, sal_Int32 nNumPeriods,
|
||||
|
||||
fIpmt *= fRate;
|
||||
|
||||
RETURN_FINITE( fIpmt );
|
||||
return finiteOrThrow( fIpmt );
|
||||
}
|
||||
|
||||
|
||||
@@ -201,11 +201,11 @@ double SAL_CALL AnalysisAddIn::getPrice( const css::uno::Reference< css::beans::
|
||||
sal_Int32 nSettle, sal_Int32 nMat, double fRate, double fYield, double fRedemp, sal_Int32 nFreq,
|
||||
const css::uno::Any& rOB )
|
||||
{
|
||||
if( fYield < 0.0 || fRate < 0.0 || fRedemp <= 0.0 || CHK_Freq || nSettle >= nMat )
|
||||
if( fYield < 0.0 || fRate < 0.0 || fRedemp <= 0.0 || isFreqInvalid(nFreq) || nSettle >= nMat )
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = getPrice_( GetNullDate( xOpt ), nSettle, nMat, fRate, fYield, fRedemp, nFreq, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ double SAL_CALL AnalysisAddIn::getPricedisc( const css::uno::Reference< css::bea
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = fRedemp * ( 1.0 - fDisc * GetYearDiff( GetNullDate( xOpt ), nSettle, nMat, getDateMode( xOpt, rOB ) ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -238,19 +238,19 @@ double SAL_CALL AnalysisAddIn::getPricemat( const css::uno::Reference< css::bean
|
||||
fRet -= fIssSet * fRate;
|
||||
fRet *= 100.0;
|
||||
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getMduration( const css::uno::Reference< css::beans::XPropertySet >& xOpt,
|
||||
sal_Int32 nSettle, sal_Int32 nMat, double fCoup, double fYield, sal_Int32 nFreq, const css::uno::Any& rOB )
|
||||
{
|
||||
if( fCoup < 0.0 || fYield < 0.0 || CHK_Freq )
|
||||
if( fCoup < 0.0 || fYield < 0.0 || isFreqInvalid(nFreq) )
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = GetDuration( GetNullDate( xOpt ), nSettle, nMat, fCoup, fYield, nFreq, getDateMode( xOpt, rOB ) );
|
||||
fRet /= 1.0 + ( fYield / double( nFreq ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -261,7 +261,7 @@ double SAL_CALL AnalysisAddIn::getNominal( double fRate, sal_Int32 nPeriods )
|
||||
|
||||
double fPeriods = nPeriods;
|
||||
double fRet = ( pow( fRate + 1.0, 1.0 / fPeriods ) - 1.0 ) * fPeriods;
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ double SAL_CALL AnalysisAddIn::getDollarfr( double fDollarDec, sal_Int32 nFrac )
|
||||
|
||||
fRet += fInt;
|
||||
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -301,18 +301,18 @@ double SAL_CALL AnalysisAddIn::getDollarde( double fDollarFrac, sal_Int32 nFrac
|
||||
|
||||
fRet += fInt;
|
||||
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
double SAL_CALL AnalysisAddIn::getYield( const css::uno::Reference< css::beans::XPropertySet >& xOpt,
|
||||
sal_Int32 nSettle, sal_Int32 nMat, double fCoup, double fPrice, double fRedemp, sal_Int32 nFreq, const css::uno::Any& rOB )
|
||||
{
|
||||
if( fCoup < 0.0 || fPrice <= 0.0 || fRedemp <= 0.0 || CHK_Freq || nSettle >= nMat )
|
||||
if( fCoup < 0.0 || fPrice <= 0.0 || fRedemp <= 0.0 || isFreqInvalid(nFreq) || nSettle >= nMat )
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = getYield_( GetNullDate( xOpt ), nSettle, nMat, fCoup, fPrice, fRedemp, nFreq, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -327,7 +327,7 @@ double SAL_CALL AnalysisAddIn::getYielddisc( const css::uno::Reference< css::bea
|
||||
double fRet = ( fRedemp / fPrice ) - 1.0;
|
||||
fRet /= GetYearFrac( nNullDate, nSettle, nMat, getDateMode( xOpt, rOB ) );
|
||||
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -338,7 +338,7 @@ double SAL_CALL AnalysisAddIn::getYieldmat( const css::uno::Reference< css::bean
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = GetYieldmat( GetNullDate( xOpt ), nSettle, nMat, nIssue, fRate, fPrice, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -353,7 +353,7 @@ double SAL_CALL AnalysisAddIn::getTbilleq( const css::uno::Reference< css::beans
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = ( 365 * fDisc ) / ( 360 - ( fDisc * double( nDiff ) ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -371,7 +371,7 @@ double SAL_CALL AnalysisAddIn::getTbillprice( const css::uno::Reference< css::be
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = 100.0 * ( 1.0 - fDisc * fFraction );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -389,7 +389,7 @@ double SAL_CALL AnalysisAddIn::getTbillyield( const css::uno::Reference< css::be
|
||||
fRet /= double( nDiff );
|
||||
fRet *= 360.0;
|
||||
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
// Encapsulation violation: We *know* that GetOddfprice() always
|
||||
@@ -401,11 +401,11 @@ double SAL_CALL AnalysisAddIn::getOddfprice( const css::uno::Reference< css::bea
|
||||
sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue, sal_Int32 nFirstCoup,
|
||||
double fRate, double fYield, double fRedemp, sal_Int32 nFreq, const css::uno::Any& rOB )
|
||||
{
|
||||
if( fRate < 0.0 || fYield < 0.0 || CHK_Freq || nMat <= nFirstCoup || nFirstCoup <= nSettle || nSettle <= nIssue )
|
||||
if( fRate < 0.0 || fYield < 0.0 || isFreqInvalid(nFreq) || nMat <= nFirstCoup || nFirstCoup <= nSettle || nSettle <= nIssue )
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = GetOddfprice( GetNullDate( xOpt ), nSettle, nMat, nIssue, nFirstCoup, fRate, fYield, fRedemp, nFreq, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
SAL_WNOUNREACHABLE_CODE_POP
|
||||
@@ -419,12 +419,12 @@ double SAL_CALL AnalysisAddIn::getOddfyield( const css::uno::Reference< css::bea
|
||||
sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue, sal_Int32 nFirstCoup,
|
||||
double fRate, double fPrice, double fRedemp, sal_Int32 nFreq, const css::uno::Any& rOB )
|
||||
{
|
||||
if( fRate < 0.0 || fPrice <= 0.0 || CHK_Freq || nMat <= nFirstCoup || nFirstCoup <= nSettle || nSettle <= nIssue )
|
||||
if( fRate < 0.0 || fPrice <= 0.0 || isFreqInvalid(nFreq) || nMat <= nFirstCoup || nFirstCoup <= nSettle || nSettle <= nIssue )
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = GetOddfyield( GetNullDate( xOpt ), nSettle, nMat, nIssue, nFirstCoup, fRate, fPrice, fRedemp, nFreq,
|
||||
getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
SAL_WNOUNREACHABLE_CODE_POP
|
||||
@@ -433,12 +433,12 @@ double SAL_CALL AnalysisAddIn::getOddlprice( const css::uno::Reference< css::bea
|
||||
sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nLastInterest,
|
||||
double fRate, double fYield, double fRedemp, sal_Int32 nFreq, const css::uno::Any& rOB )
|
||||
{
|
||||
if( fRate <= 0.0 || fYield < 0.0 || fRedemp <= 0.0 || CHK_Freq || nMat <= nSettle || nSettle <= nLastInterest )
|
||||
if( fRate <= 0.0 || fYield < 0.0 || fRedemp <= 0.0 || isFreqInvalid(nFreq) || nMat <= nSettle || nSettle <= nLastInterest )
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = GetOddlprice( GetNullDate( xOpt ), nSettle, nMat, nLastInterest, fRate, fYield, fRedemp, nFreq,
|
||||
getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -446,12 +446,12 @@ double SAL_CALL AnalysisAddIn::getOddlyield( const css::uno::Reference< css::bea
|
||||
sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nLastInterest,
|
||||
double fRate, double fPrice, double fRedemp, sal_Int32 nFreq, const css::uno::Any& rOB )
|
||||
{
|
||||
if( fRate <= 0.0 || fPrice <= 0.0 || fRedemp <= 0.0 || CHK_Freq || nMat <= nSettle || nSettle <= nLastInterest )
|
||||
if( fRate <= 0.0 || fPrice <= 0.0 || fRedemp <= 0.0 || isFreqInvalid(nFreq) || nMat <= nSettle || nSettle <= nLastInterest )
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = GetOddlyield( GetNullDate( xOpt ), nSettle, nMat, nLastInterest, fRate, fPrice, fRedemp, nFreq,
|
||||
getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
// XIRR helper functions
|
||||
@@ -571,7 +571,7 @@ double SAL_CALL AnalysisAddIn::getXirr(
|
||||
|
||||
if( bContLoop )
|
||||
throw css::lang::IllegalArgumentException();
|
||||
RETURN_FINITE( fResultRate );
|
||||
return finiteOrThrow( fResultRate );
|
||||
}
|
||||
|
||||
|
||||
@@ -596,7 +596,7 @@ double SAL_CALL AnalysisAddIn::getXnpv(
|
||||
for( sal_uInt32 i = 0 ; i < nNum ; i++ )
|
||||
fRet += aValList.Get( i ) / ( pow( fRate, ( aDateList.Get( i ) - fNull ) / 365.0 ) );
|
||||
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -607,7 +607,7 @@ double SAL_CALL AnalysisAddIn::getIntrate( const css::uno::Reference< css::beans
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = ( ( fRedemp / fInvest ) - 1.0 ) / GetYearDiff( GetNullDate( xOpt ), nSettle, nMat, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -615,7 +615,7 @@ double SAL_CALL AnalysisAddIn::getCoupncd( const css::uno::Reference< css::beans
|
||||
sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, const css::uno::Any& rOB )
|
||||
{
|
||||
double fRet = GetCoupncd( GetNullDate( xOpt ), nSettle, nMat, nFreq, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -623,7 +623,7 @@ double SAL_CALL AnalysisAddIn::getCoupdays( const css::uno::Reference< css::bean
|
||||
sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, const css::uno::Any& rOB )
|
||||
{
|
||||
double fRet = GetCoupdays( GetNullDate( xOpt ), nSettle, nMat, nFreq, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -631,7 +631,7 @@ double SAL_CALL AnalysisAddIn::getCoupdaysnc( const css::uno::Reference< css::be
|
||||
sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, const css::uno::Any& rOB )
|
||||
{
|
||||
double fRet = GetCoupdaysnc( GetNullDate( xOpt ), nSettle, nMat, nFreq, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -639,7 +639,7 @@ double SAL_CALL AnalysisAddIn::getCoupdaybs( const css::uno::Reference< css::bea
|
||||
sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, const css::uno::Any& rOB )
|
||||
{
|
||||
double fRet = GetCoupdaybs( GetNullDate( xOpt ), nSettle, nMat, nFreq, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -647,7 +647,7 @@ double SAL_CALL AnalysisAddIn::getCouppcd( const css::uno::Reference< css::beans
|
||||
sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, const css::uno::Any& rOB )
|
||||
{
|
||||
double fRet = GetCouppcd( GetNullDate( xOpt ), nSettle, nMat, nFreq, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -655,7 +655,7 @@ double SAL_CALL AnalysisAddIn::getCoupnum( const css::uno::Reference< css::beans
|
||||
sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, const css::uno::Any& rOB )
|
||||
{
|
||||
double fRet = GetCoupnum( GetNullDate( xOpt ), nSettle, nMat, nFreq, getDateMode( xOpt, rOB ) );
|
||||
RETURN_FINITE( fRet );
|
||||
return finiteOrThrow( fRet );
|
||||
}
|
||||
|
||||
|
||||
@@ -668,7 +668,7 @@ double SAL_CALL AnalysisAddIn::getFvschedule( double fPrinc, const css::uno::Seq
|
||||
for( sal_uInt32 i = 0; i < aSchedList.Count(); ++i )
|
||||
fPrinc *= 1.0 + aSchedList.Get(i);
|
||||
|
||||
RETURN_FINITE( fPrinc );
|
||||
return finiteOrThrow( fPrinc );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -45,23 +45,14 @@ constexpr OUStringLiteral ADDIN_SERVICE = u"com.sun.star.sheet.AddIn";
|
||||
constexpr OUStringLiteral MY_SERVICE = u"com.sun.star.sheet.addin.PricingFunctions";
|
||||
constexpr OUStringLiteral MY_IMPLNAME = u"com.sun.star.sheet.addin.PricingFunctionsImpl";
|
||||
|
||||
#define UNIQUE false // function name does not exist in Calc
|
||||
|
||||
#define STDPAR false // all parameters are described
|
||||
|
||||
#define FUNCDATA( FuncName, CompName, ParamCount, Category, Double, IntPar ) \
|
||||
{ "get" #FuncName, PRICING_FUNCNAME_##FuncName, PRICING_FUNCDESC_##FuncName, CompName, ParamCount, Category, Double, IntPar }
|
||||
|
||||
const ScaFuncDataBase pFuncDataArr[] =
|
||||
{
|
||||
FUNCDATA(OptBarrier, "OPT_BARRIER", 13, ScaCategory::Finance, UNIQUE, STDPAR),
|
||||
FUNCDATA(OptTouch, "OPT_TOUCH", 11, ScaCategory::Finance, UNIQUE, STDPAR),
|
||||
FUNCDATA(OptProbHit, "OPT_PROB_HIT", 6, ScaCategory::Finance, UNIQUE, STDPAR),
|
||||
FUNCDATA(OptProbInMoney, "OPT_PROB_INMONEY", 8, ScaCategory::Finance, UNIQUE, STDPAR)
|
||||
{ "getOptBarrier", PRICING_FUNCNAME_OptBarrier, PRICING_FUNCDESC_OptBarrier, "OPT_BARRIER", 13, ScaCategory::Finance, false, false },
|
||||
{ "getOptTouch", PRICING_FUNCNAME_OptTouch, PRICING_FUNCDESC_OptTouch, "OPT_TOUCH", 11, ScaCategory::Finance, false, false },
|
||||
{ "getOptProbHit", PRICING_FUNCNAME_OptProbHit, PRICING_FUNCDESC_OptProbHit, "OPT_PROB_HIT", 6, ScaCategory::Finance, false, false },
|
||||
{ "getOptProbInMoney", PRICING_FUNCNAME_OptProbInMoney, PRICING_FUNCDESC_OptProbInMoney, "OPT_PROB_INMONEY", 8, ScaCategory::Finance, false, false },
|
||||
};
|
||||
|
||||
#undef FUNCDATA
|
||||
|
||||
ScaFuncData::ScaFuncData( const ScaFuncDataBase& rBaseData ) :
|
||||
aIntName( OUString::createFromAscii( rBaseData.pIntName ) ),
|
||||
pUINameID( rBaseData.pUINameID ),
|
||||
@@ -437,7 +428,9 @@ double SAL_CALL ScaPricingAddIn::getOptBarrier( double spot, double vol,
|
||||
double fRet=bs::barrier(spot,vol,r,rf,T,strike, barrier_low,barrier_up,
|
||||
rebate,pc,kio,bcont,greek);
|
||||
|
||||
RETURN_FINITE( fRet );
|
||||
if (!std::isfinite(fRet))
|
||||
throw css::lang::IllegalArgumentException();
|
||||
return fRet;
|
||||
}
|
||||
|
||||
// OPT_TOUCH(...)
|
||||
@@ -463,7 +456,9 @@ double SAL_CALL ScaPricingAddIn::getOptTouch( double spot, double vol,
|
||||
double fRet=bs::touch(spot,vol,r,rf,T,barrier_low,barrier_up,
|
||||
fd,kio,bcont,greek);
|
||||
|
||||
RETURN_FINITE( fRet );
|
||||
if (!std::isfinite(fRet))
|
||||
throw css::lang::IllegalArgumentException();
|
||||
return fRet;
|
||||
}
|
||||
|
||||
// OPT_PRB_HIT(...)
|
||||
@@ -478,7 +473,9 @@ double SAL_CALL ScaPricingAddIn::getOptProbHit( double spot, double vol,
|
||||
|
||||
double fRet=bs::prob_hit(spot,vol,mu,T,barrier_low,barrier_up);
|
||||
|
||||
RETURN_FINITE( fRet );
|
||||
if (!std::isfinite(fRet))
|
||||
throw css::lang::IllegalArgumentException();
|
||||
return fRet;
|
||||
}
|
||||
|
||||
// OPT_PROB_INMONEY(...)
|
||||
@@ -499,7 +496,9 @@ double SAL_CALL ScaPricingAddIn::getOptProbInMoney( double spot, double vol,
|
||||
|
||||
double fRet=bs::prob_in_money(spot,vol,mu,T,K,barrier_low,barrier_up,pc);
|
||||
|
||||
RETURN_FINITE( fRet );
|
||||
if (!std::isfinite(fRet))
|
||||
throw css::lang::IllegalArgumentException();
|
||||
return fRet;
|
||||
}
|
||||
|
||||
OUString ScaPricingAddIn::ScaResId(TranslateId aResId)
|
||||
|
||||
@@ -39,8 +39,6 @@
|
||||
|
||||
namespace com::sun::star::lang { class XMultiServiceFactory; }
|
||||
|
||||
#define RETURN_FINITE(d) if( !std::isfinite( d ) ) throw css::lang::IllegalArgumentException(); return d;
|
||||
|
||||
|
||||
namespace sca::pricing {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user