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 #ifndef SC_INTERPRE_HXX
21 #define SC_INTERPRE_HXX
24 #include <rtl/math.hxx>
25 #include <rtl/ustring.hxx>
26 #include "formula/errorcodes.hxx"
27 #include "formula/tokenarray.hxx"
29 #include "scmatrix.hxx"
30 #include "externalrefmgr.hxx"
31 #include "calcconfig.hxx"
40 class SvNumberFormatter
;
43 struct ScDBQueryParamBase
;
47 struct ScCompareOptions
;
48 struct ScSingleRefData
;
49 struct ScComplexRefData
;
54 struct ScRefCellValue
;
56 #define MAXSTACK (4096 / sizeof(formula::FormulaToken*))
61 DECL_FIXEDMEMPOOL_NEWDEL( ScTokenStack
)
62 formula::FormulaToken
* pPointer
[ MAXSTACK
];
67 ifSUMSQ
, // Sums of squares
70 ifCOUNT
, // Count Values
71 ifCOUNT2
, // Count Values (not empty)
78 ifSUMIF
, // Conditional sum
79 ifAVERAGEIF
// Conditional average
84 ifSUMIFS
, // Multi-Conditional sum
85 ifAVERAGEIFS
, // Multi-Conditional average
86 ifCOUNTIFS
// Multi-Conditional count
89 struct FormulaTokenRef_less
91 bool operator () ( const formula::FormulaConstTokenRef
& r1
, const formula::FormulaConstTokenRef
& r2
) const
92 { return r1
.get() < r2
.get(); }
94 typedef ::std::map
< const formula::FormulaConstTokenRef
, formula::FormulaTokenRef
, FormulaTokenRef_less
> ScTokenMatrixMap
;
98 // distibution function objects need the GetxxxDist methods
99 friend class ScGammaDistFunction
;
100 friend class ScBetaDistFunction
;
101 friend class ScTDistFunction
;
102 friend class ScFDistFunction
;
103 friend class ScChiDistFunction
;
104 friend class ScChiSqDistFunction
;
107 DECL_FIXEDMEMPOOL_NEWDEL( ScInterpreter
)
109 static void SetGlobalConfig(const ScCalcConfig
& rConfig
);
110 static const ScCalcConfig
& GetGlobalConfig();
112 static void GlobalExit(); // called by ScGlobal::Clear()
114 /// Could string be a regular expression?
115 /// If pDoc!=NULL the document options are taken into account and if
116 /// RegularExpressions are disabled the function returns false regardless
117 /// of the string content.
118 static bool MayBeRegExp( const OUString
& rStr
, const ScDocument
* pDoc
);
120 /// Fail safe division, returning an errDivisionByZero coded into a double
121 /// if denominator is 0.0
122 static inline double div( const double& fNumerator
, const double& fDenominator
);
124 ScMatrixRef
GetNewMat(SCSIZE nC
, SCSIZE nR
, bool bEmpty
= false);
132 VolatileType
GetVolatileType() const;
135 static ScCalcConfig maGlobalConfig
;
137 static ScTokenStack
* pGlobalStack
;
138 static bool bGlobalStackInUse
;
140 formula::FormulaTokenIterator aCode
;
144 formula::FormulaTokenRef xResult
;
145 ScJumpMatrix
* pJumpMatrix
; // currently active array condition, if any
146 ScTokenMatrixMap
* pTokenMatrixMap
; // map ScToken* to formula::FormulaTokenRef if in array condition
147 ScFormulaCell
* pMyFormulaCell
; // the cell of this formula expression
148 SvNumberFormatter
* pFormatter
;
150 const formula::FormulaToken
*
151 pCur
; // current token
152 OUString aTempStr
; // for GetString()
153 ScTokenStack
* pStackObj
; // contains the stacks
154 formula::FormulaToken
** pStack
; // the current stack
155 sal_uInt16 nGlobalError
; // global (local to this formula expression) error
156 sal_uInt16 sp
; // stack pointer
157 sal_uInt16 maxsp
; // the maximal used stack pointer
158 sal_uLong nFuncFmtIndex
; // NumberFormatIndex of a function
159 sal_uLong nCurFmtIndex
; // current NumberFormatIndex
160 sal_uLong nRetFmtIndex
; // NumberFormatIndex of an expression, if any
161 short nFuncFmtType
; // NumberFormatType of a function
162 short nCurFmtType
; // current NumberFormatType
163 short nRetFmtType
; // NumberFormatType of an expression
164 sal_uInt16 mnStringNoValueError
; // the error set in ConvertStringToValue() if no value
165 bool glSubTotal
; // flag for subtotal functions
166 sal_uInt8 cPar
; // current count of parameters
167 bool bCalcAsShown
; // precision as shown
168 bool bMatrixFormula
; // formula cell is a matrix formula
170 VolatileType meVolatileType
;
172 // nMust <= nAct <= nMax ? ok : PushError
173 inline bool MustHaveParamCount( short nAct
, short nMust
);
174 inline bool MustHaveParamCount( short nAct
, short nMust
, short nMax
);
175 inline bool MustHaveParamCountMin( short nAct
, short nMin
);
176 void PushParameterExpected();
177 void PushIllegalParameter();
178 void PushIllegalArgument();
182 // Functions for accessing a document
184 void ReplaceCell( ScAddress
& ); // for TableOp
185 void ReplaceCell( SCCOL
& rCol
, SCROW
& rRow
, SCTAB
& rTab
); // for TableOp
186 bool IsTableOpInRange( const ScRange
& );
187 sal_uLong
GetCellNumberFormat( const ScAddress
& rPos
, ScRefCellValue
& rCell
);
188 double ConvertStringToValue( const String
& );
189 double GetCellValue( const ScAddress
&, ScRefCellValue
& rCell
);
190 double GetCellValueOrZero( const ScAddress
&, ScRefCellValue
& rCell
);
191 double GetValueCellValue( const ScAddress
&, double fOrig
);
192 void GetCellString( OUString
& rStr
, ScRefCellValue
& rCell
);
193 sal_uInt16
GetCellErrCode( const ScRefCellValue
& rCell
);
195 bool CreateDoubleArr(SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
196 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
, sal_uInt8
* pCellArr
);
197 bool CreateStringArr(SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
198 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
, sal_uInt8
* pCellArr
);
199 bool CreateCellArr(SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
200 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
, sal_uInt8
* pCellArr
);
204 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
205 passed is not formula::FormulaErrorToken.
206 Increments RefCount of the original token if not substituted. */
207 void Push( formula::FormulaToken
& r
);
209 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
210 Used to push RPN tokens or from within Push() or tokens that are already
211 explicit formula::FormulaErrorToken. Increments RefCount. */
212 void PushWithoutError( formula::FormulaToken
& r
);
214 /** Clones the token to be pushed or substitutes with formula::FormulaErrorToken if
215 nGlobalError is set and the token passed is not formula::FormulaErrorToken. */
216 void PushTempToken( const formula::FormulaToken
& );
218 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
219 passed is not formula::FormulaErrorToken.
220 Increments RefCount of the original token if not substituted.
221 ATTENTION! The token had to be allocated with `new' and must not be used
222 after this call if no RefCount was set because possibly it gets immediately
223 deleted in case of an errStackOverflow or if substituted with formula::FormulaErrorToken! */
224 void PushTempToken( formula::FormulaToken
* );
226 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
227 Used to push tokens from within PushTempToken() or tokens that are already
228 explicit formula::FormulaErrorToken. Increments RefCount.
229 ATTENTION! The token had to be allocated with `new' and must not be used
230 after this call if no RefCount was set because possibly it gets immediately
231 decremented again and thus deleted in case of an errStackOverflow! */
232 void PushTempTokenWithoutError( formula::FormulaToken
* );
234 /** If nGlobalError is set push formula::FormulaErrorToken.
235 If nGlobalError is not set do nothing.
236 Used in PushTempToken() and alike to simplify handling.
237 @return: <TRUE/> if nGlobalError. */
238 inline bool IfErrorPushError()
242 PushTempTokenWithoutError( new formula::FormulaErrorToken( nGlobalError
));
248 /** Obtain cell result / content from address and push as temp token.
249 bDisplayEmptyAsString is passed to ScEmptyCell in case of an empty cell
250 result. Also obtain number format and type if _both_, type and index
251 pointer, are not NULL. */
252 void PushCellResultToken( bool bDisplayEmptyAsString
, const ScAddress
& rAddress
,
253 short * pRetTypeExpr
, sal_uLong
* pRetIndexExpr
);
255 formula::FormulaTokenRef
PopToken();
259 const OUString
& PopString();
260 void ValidateRef( const ScSingleRefData
& rRef
);
261 void ValidateRef( const ScComplexRefData
& rRef
);
262 void ValidateRef( const ScRefList
& rRefList
);
263 void SingleRefToVars( const ScSingleRefData
& rRef
, SCCOL
& rCol
, SCROW
& rRow
, SCTAB
& rTab
);
264 void PopSingleRef( ScAddress
& );
265 void PopSingleRef(SCCOL
& rCol
, SCROW
&rRow
, SCTAB
& rTab
);
266 void DoubleRefToRange( const ScComplexRefData
&, ScRange
&, bool bDontCheckForTableOp
= false );
267 /** If formula::StackVar formula::svDoubleRef pop ScDoubleRefToken and return values of
269 Else if StackVar svRefList return values of the ScComplexRefData where
270 rRefInList is pointing to. rRefInList is incremented. If rRefInList was the
271 last element in list pop ScRefListToken and set rRefInList to 0, else
272 rParam is incremented (!) to allow usage as in
273 while(nParamCount--) PopDoubleRef(aRange,nParamCount,nRefInList);
275 void PopDoubleRef( ScRange
& rRange
, short & rParam
, size_t & rRefInList
);
276 void PopDoubleRef( ScRange
&, bool bDontCheckForTableOp
= false );
277 void DoubleRefToVars( const ScToken
* p
,
278 SCCOL
& rCol1
, SCROW
&rRow1
, SCTAB
& rTab1
,
279 SCCOL
& rCol2
, SCROW
&rRow2
, SCTAB
& rTab2
,
280 bool bDontCheckForTableOp
= false );
281 ScDBRangeBase
* PopDBDoubleRef();
282 void PopDoubleRef(SCCOL
& rCol1
, SCROW
&rRow1
, SCTAB
& rTab1
,
283 SCCOL
& rCol2
, SCROW
&rRow2
, SCTAB
& rTab2
,
284 bool bDontCheckForTableOp
= false );
285 void PopExternalSingleRef(sal_uInt16
& rFileId
, String
& rTabName
, ScSingleRefData
& rRef
);
286 void PopExternalSingleRef(ScExternalRefCache::TokenRef
& rToken
, ScExternalRefCache::CellFormat
* pFmt
= NULL
);
287 void PopExternalSingleRef(sal_uInt16
& rFileId
, String
& rTabName
, ScSingleRefData
& rRef
,
288 ScExternalRefCache::TokenRef
& rToken
, ScExternalRefCache::CellFormat
* pFmt
= NULL
);
289 void PopExternalDoubleRef(sal_uInt16
& rFileId
, String
& rTabName
, ScComplexRefData
& rRef
);
290 void PopExternalDoubleRef(ScExternalRefCache::TokenArrayRef
& rArray
);
291 void PopExternalDoubleRef(ScMatrixRef
& rMat
);
292 void GetExternalDoubleRef(sal_uInt16 nFileId
, const String
& rTabName
, const ScComplexRefData
& aData
, ScExternalRefCache::TokenArrayRef
& rArray
);
293 bool PopDoubleRefOrSingleRef( ScAddress
& rAdr
);
294 void PopDoubleRefPushMatrix();
295 // If MatrixFormula: convert formula::svDoubleRef to svMatrix, create JumpMatrix.
296 // Else convert area reference parameters marked as ForceArray to array.
297 // Returns true if JumpMatrix created.
298 bool ConvertMatrixParameters();
299 inline void MatrixDoubleRefToMatrix(); // if MatrixFormula: PopDoubleRefPushMatrix
300 // If MatrixFormula or ForceArray: ConvertMatrixParameters()
301 inline bool MatrixParameterConversion();
302 ScMatrixRef
PopMatrix();
303 void QueryMatrixType(ScMatrixRef
& xMat
, short& rRetTypeExpr
, sal_uLong
& rRetIndexExpr
);
305 void PushDouble(double nVal
);
306 void PushInt( int nVal
);
307 void PushStringBuffer( const sal_Unicode
* pString
);
308 void PushString( const String
& rString
);
309 void PushSingleRef(SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
310 void PushDoubleRef(SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
311 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
);
312 void PushExternalSingleRef(sal_uInt16 nFileId
, const String
& rTabName
,
313 SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
314 void PushExternalDoubleRef(sal_uInt16 nFileId
, const String
& rTabName
,
315 SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
316 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
);
317 void PushMatrix(const ScMatrixRef
& pMat
);
318 void PushError( sal_uInt16 nError
);
319 /// Raw stack type without default replacements.
320 formula::StackVar
GetRawStackType();
321 /// Stack type with replacement of defaults, e.g. svMissing and formula::svEmptyCell will result in formula::svDouble.
322 formula::StackVar
GetStackType();
323 // peek StackType of Parameter, Parameter 1 == TOS, 2 == TOS-1, ...
324 formula::StackVar
GetStackType( sal_uInt8 nParam
);
325 sal_uInt8
GetByte() { return cPar
; }
326 // generates a position-dependent SingleRef out of a DoubleRef
327 bool DoubleRefToPosSingleRef( const ScRange
& rRange
, ScAddress
& rAdr
);
328 double GetDoubleFromMatrix(const ScMatrixRef
& pMat
);
330 double GetDoubleWithDefault(double nDefault
);
332 bool GetBool() { return GetDouble() != 0.0; }
333 const OUString
& GetString();
334 const OUString
& GetStringFromMatrix(const ScMatrixRef
& pMat
);
335 // pop matrix and obtain one element, upper left or according to jump matrix
336 ScMatValType
GetDoubleOrStringFromMatrix( double& rDouble
, OUString
& rString
);
337 ScMatrixRef
CreateMatrixFromDoubleRef( const formula::FormulaToken
* pToken
,
338 SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
339 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
);
340 inline ScTokenMatrixMap
& GetTokenMatrixMap();
341 ScTokenMatrixMap
* CreateTokenMatrixMap();
342 ScMatrixRef
GetMatrix();
343 void ScTableOp(); // repeated operations
344 void ScErrCell(); // special handling for
347 // common helper functions
349 void SetMaxIterationCount(sal_uInt16 n
);
350 inline void CurFmtToFuncFmt()
351 { nFuncFmtType
= nCurFmtType
; nFuncFmtIndex
= nCurFmtIndex
; }
352 // Check for String overflow of rResult+rAdd and set error and erase rResult
353 // if so. Return true if ok, false if overflow
354 inline bool CheckStringResultLen( String
& rResult
, const String
& rAdd
);
355 // Set error according to rVal, and set rVal to 0.0 if there was an error.
356 inline void TreatDoubleError( double& rVal
);
357 // Lookup using ScLookupCache, @returns true if found and result address
358 bool LookupQueryWithCache( ScAddress
& o_rResultPos
,
359 const ScQueryParam
& rParam
) const;
362 void ScIfError( bool bNAonly
);
365 // Be sure to only call this if pStack[sp-nStackLevel] really contains a
366 // ScJumpMatrixToken, no further checks are applied!
367 // Returns true if last jump was executed and result matrix pushed.
368 bool JumpMatrix( short nStackLevel
);
371 NULL means case sensitivity document option is to be used!
373 double CompareFunc( const ScCompare
& rComp
, ScCompareOptions
* pOptions
= NULL
);
376 NULL means case sensitivity document option is to be used!
378 ScMatrixRef
CompareMat( ScCompareOptions
* pOptions
= NULL
);
379 ScMatrixRef
QueryMat( const ScMatrixRef
& pMat
, ScCompareOptions
& rOptions
);
385 void ScGreaterEqual();
391 void ScPercentSign();
419 void ScCosecantHyp();
428 void ScIsNonString();
432 void ScCellExternal();
454 void ScNumberValue();
461 void ScMin( bool bTextAsZero
= false );
462 void ScMax( bool bTextAsZero
= false );
463 double IterateParameters( ScIterFunc
, bool bTextAsZero
= false );
467 void ScAverage( bool bTextAsZero
= false );
470 void GetStVarParams( double& rVal
, double& rValCount
, bool bTextAsZero
= false );
471 void ScVar( bool bTextAsZero
= false );
472 void ScVarP( bool bTextAsZero
= false );
473 void ScStDev( bool bTextAsZero
= false );
474 void ScStDevP( bool bTextAsZero
= false );
482 double IterateParametersIf( ScIterFuncIf
);
486 double IterateParametersIfs( ScIterFuncIfs
);
490 void ScCountEmptyCells();
496 // If upon call rMissingField==true then the database field parameter may be
497 // missing (Xcl DCOUNT() syntax), or may be faked as missing by having the
498 // value 0.0 or being exactly the entire database range reference (old SO
499 // compatibility). If this was the case then rMissingField is set to true upon
500 // return. If rMissingField==false upon call all "missing cases" are considered
502 ScDBQueryParamBase
* GetDBParams( bool& rMissingField
);
504 void DBIterator( ScIterFunc
);
513 void GetDBStVarParams( double& rVal
, double& rValCount
);
519 void ScAddressFunc();
540 bool SetSbxVariable( SbxVariable
* pVar
, const ScAddress
& );
541 bool SetSbxVariable( SbxVariable
* pVar
, SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
544 void ScColRowNameAuto();
545 void ScGetPivotData();
555 /** Obtain the date serial number for a given date.
557 If false, nYear < 100 takes the two-digit year setting into account,
558 and rollover of invalid calendar dates takes place, e.g. 1999-02-31 =>
560 If true, the date passed must be a valid Gregorian calendar date. No
561 two-digit expanding or rollover is done.
563 @param bCheckGregorian
564 If true, date must be Gregorian, i.e. >= 1582-10-15.
565 If false, don't care, any valid date >= 0-1-1 will do.
567 double GetDateSerial( sal_Int16 nYear
, sal_Int16 nMonth
, sal_Int16 nDay
, bool bStrict
, bool bCheckGregorian
);
574 void ScGetDayOfWeek();
575 void ScGetWeekOfYear();
576 void ScEasterSunday();
587 void RoundNumber( rtl_math_RoundingMode eMode
);
591 void ScGetDateValue();
592 void ScGetTimeValue();
597 void ScGetDiffDate();
598 void ScGetDiffDate360();
613 void ScEuroConvert();
615 // financial functions
621 double ScGetBw(double fZins
, double fZzr
, double fRmz
,
622 double fZw
, double fF
);
625 double ScGetGDA(double fWert
, double fRest
, double fDauer
,
626 double fPeriode
, double fFaktor
);
629 double ScInterVDB(double fWert
,double fRest
,double fDauer
,double fDauer1
,
630 double fPeriode
,double fFaktor
);
634 double ScGetRmz(double fZins
, double fZzr
, double fBw
,
635 double fZw
, double fF
);
638 double ScGetZw(double fZins
, double fZzr
, double fRmz
,
639 double fBw
, double fF
);
642 bool RateIteration(double fNper
, double fPayment
, double fPv
,
643 double fFv
, double fPayType
, double& fGuess
);
645 double ScGetZinsZ(double fZins
, double fZr
, double fZzr
, double fBw
,
646 double fZw
, double fF
, double& fRmz
);
655 double ScGetGCD(double fx
, double fy
);
661 void MEMat(const ScMatrixRef
& mM
, SCSIZE n
);
668 ScMatrixRef
MatConcat(const ScMatrixRef
& pMat1
, const ScMatrixRef
& pMat2
);
674 bool CalculateSkew(double& fSum
,double& fCount
,double& vSum
,std::vector
<double>& values
);
675 void CalculateSkewOrSkewp( bool bSkewp
);
676 void CalculateSlopeIntercept(bool bSlope
);
677 void CalculateSmallLarge(bool bSmall
);
678 void CalculatePearsonCovar(bool _bPearson
,bool _bStexy
);
679 bool CalculateTest( bool _bTemplin
680 ,const SCSIZE nC1
, const SCSIZE nC2
,const SCSIZE nR1
,const SCSIZE nR2
681 ,const ScMatrixRef
& pMat1
,const ScMatrixRef
& pMat2
682 ,double& fT
,double& fF
);
683 void CalculateLookup(bool HLookup
);
684 bool FillEntry(ScQueryEntry
& rEntry
);
685 void CalculateAddSub(bool _bSub
);
686 void CalculateTrendGrowth(bool _bGrowth
);
687 void CalulateRGPRKP(bool _bRKP
);
688 void CalculateSumX2MY2SumX2DY2(bool _bSumX2DY2
);
689 void CalculateMatrixValue(const ScMatrix
* pMat
,SCSIZE nC
,SCSIZE nR
);
690 bool CheckMatrix(bool _bLOG
,sal_uInt8
& nCase
,SCSIZE
& nCX
,SCSIZE
& nCY
,SCSIZE
& nRX
,SCSIZE
& nRY
,SCSIZE
& M
,SCSIZE
& N
,ScMatrixRef
& pMatX
,ScMatrixRef
& pMatY
);
697 double phi(double x
);
698 double integralPhi(double x
);
699 double taylor(double* pPolynom
, sal_uInt16 nMax
, double x
);
700 double gauss(double x
);
701 double gaussinv(double x
);
702 double GetBetaDist(double x
, double alpha
, double beta
); //cumulative distribution function
703 double GetBetaDistPDF(double fX
, double fA
, double fB
); //probability density function)
704 double GetChiDist(double fChi
, double fDF
); // for LEGACY.CHIDIST, returns right tail
705 double GetChiSqDistCDF(double fX
, double fDF
); // for CHISQDIST, returns left tail
706 double GetChiSqDistPDF(double fX
, double fDF
); // probability density function
707 double GetFDist(double x
, double fF1
, double fF2
);
708 double GetTDist(double T
, double fDF
);
709 double Fakultaet(double x
);
710 double BinomKoeff(double n
, double k
);
711 double GetGamma(double x
);
712 double GetLogGamma(double x
);
713 double GetBeta(double fAlpha
, double fBeta
);
714 double GetLogBeta(double fAlpha
, double fBeta
);
715 double GetBinomDistPMF(double x
, double n
, double p
); //probability mass function
720 void ScStdNormDist();
729 void ScPoissonDist();
732 void ScVariationen();
733 void ScVariationen2();
735 void ScHypGeomDist();
736 void ScLogNormDist();
740 void ScChiDist(); // for LEGACY.CHIDIST, returns right tail
741 void ScChiSqDist(); // returns left tail or density
742 void ScChiSqInv(); //invers to CHISQDIST
750 void ScNegBinomDist();
758 double GetMedian( ::std::vector
<double> & rArray
);
759 double GetPercentile( ::std::vector
<double> & rArray
, double fPercentile
);
760 void GetNumberSequenceArray( sal_uInt8 nParamCount
, ::std::vector
<double>& rArray
);
761 void GetSortArray(sal_uInt8 nParamCount
, ::std::vector
<double>& rSortArray
, ::std::vector
<long>* pIndexOrder
= NULL
);
762 void QuickSort(::std::vector
<double>& rSortArray
, ::std::vector
<long>* pIndexOrder
= NULL
);
772 void ScPercentrank();
781 void ScProbability();
791 static const double fMaxGammaArgument
;
793 double GetGammaContFraction(double fA
,double fX
);
794 double GetGammaSeries(double fA
,double fX
);
795 double GetLowRegIGamma(double fA
,double fX
); // lower regularized incomplete gamma function, GAMMAQ
796 double GetUpRegIGamma(double fA
,double fX
); // upper regularized incomplete gamma function, GAMMAP
797 // probability density function; fLambda is "scale" parameter
798 double GetGammaDistPDF(double fX
, double fAlpha
, double fLambda
);
799 // cumulative distribution function; fLambda is "scale" parameter
800 double GetGammaDist(double fX
, double fAlpha
, double fLambda
);
803 ScInterpreter( ScFormulaCell
* pCell
, ScDocument
* pDoc
,
804 const ScAddress
&, ScTokenArray
& );
807 formula::StackVar
Interpret();
809 void SetError(sal_uInt16 nError
)
810 { if (nError
&& !nGlobalError
) nGlobalError
= nError
; }
812 sal_uInt16
GetError() const { return nGlobalError
; }
813 formula::StackVar
GetResultType() const { return xResult
->GetType(); }
814 const String
& GetStringResult() const { return xResult
->GetString(); }
815 double GetNumResult() const { return xResult
->GetDouble(); }
816 formula::FormulaTokenRef
GetResultToken() const { return xResult
; }
817 short GetRetFormatType() const { return nRetFmtType
; }
818 sal_uLong
GetRetFormatIndex() const { return nRetFmtIndex
; }
821 inline void ScInterpreter::MatrixDoubleRefToMatrix()
823 if ( bMatrixFormula
&& GetStackType() == formula::svDoubleRef
)
825 GetTokenMatrixMap(); // make sure it exists, create if not.
826 PopDoubleRefPushMatrix();
830 inline bool ScInterpreter::MatrixParameterConversion()
832 if ( (bMatrixFormula
|| pCur
->HasForceArray()) && !pJumpMatrix
&& sp
> 0 )
833 return ConvertMatrixParameters();
837 inline ScTokenMatrixMap
& ScInterpreter::GetTokenMatrixMap()
839 if (!pTokenMatrixMap
)
840 pTokenMatrixMap
= CreateTokenMatrixMap();
841 return *pTokenMatrixMap
;
844 inline bool ScInterpreter::MustHaveParamCount( short nAct
, short nMust
)
849 PushParameterExpected();
851 PushIllegalParameter();
855 inline bool ScInterpreter::MustHaveParamCount( short nAct
, short nMust
, short nMax
)
857 if ( nMust
<= nAct
&& nAct
<= nMax
)
860 PushParameterExpected();
862 PushIllegalParameter();
866 inline bool ScInterpreter::MustHaveParamCountMin( short nAct
, short nMin
)
870 PushParameterExpected();
874 inline bool ScInterpreter::CheckStringResultLen( String
& rResult
, const String
& rAdd
)
876 if ( (sal_uLong
) rResult
.Len() + rAdd
.Len() > STRING_MAXLEN
)
878 SetError( errStringOverflow
);
885 inline void ScInterpreter::TreatDoubleError( double& rVal
)
887 if ( !::rtl::math::isFinite( rVal
) )
889 sal_uInt16 nErr
= GetDoubleErrorValue( rVal
);
893 SetError( errNoValue
);
898 inline double ScInterpreter::div( const double& fNumerator
, const double& fDenominator
)
900 return (fDenominator
!= 0.0) ? (fNumerator
/ fDenominator
) :
901 CreateDoubleError( errDivisionByZero
);
906 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */