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 <tools/string.hxx>
27 #include "formula/errorcodes.hxx"
28 #include "formula/tokenarray.hxx"
31 #include "externalrefmgr.hxx"
32 #include "calcconfig.hxx"
40 class SvNumberFormatter
;
43 struct ScDBQueryParamBase
;
46 struct ScSingleRefData
;
47 struct ScComplexRefData
;
51 struct ScRefCellValue
;
57 struct CompareOptions
;
63 class SharedStringPool
;
67 #define MAXSTACK (4096 / sizeof(formula::FormulaToken*))
72 DECL_FIXEDMEMPOOL_NEWDEL( ScTokenStack
)
73 formula::FormulaToken
* pPointer
[ MAXSTACK
];
78 ifSUMSQ
, // Sums of squares
81 ifCOUNT
, // Count Values
82 ifCOUNT2
, // Count Values (not empty)
89 ifSUMIF
, // Conditional sum
90 ifAVERAGEIF
// Conditional average
95 ifSUMIFS
, // Multi-Conditional sum
96 ifAVERAGEIFS
, // Multi-Conditional average
97 ifCOUNTIFS
// Multi-Conditional count
100 struct FormulaTokenRef_less
102 bool operator () ( const formula::FormulaConstTokenRef
& r1
, const formula::FormulaConstTokenRef
& r2
) const
103 { return r1
.get() < r2
.get(); }
105 typedef ::std::map
< const formula::FormulaConstTokenRef
, formula::FormulaTokenRef
, FormulaTokenRef_less
> ScTokenMatrixMap
;
109 // distibution function objects need the GetxxxDist methods
110 friend class ScGammaDistFunction
;
111 friend class ScBetaDistFunction
;
112 friend class ScTDistFunction
;
113 friend class ScFDistFunction
;
114 friend class ScChiDistFunction
;
115 friend class ScChiSqDistFunction
;
118 DECL_FIXEDMEMPOOL_NEWDEL( ScInterpreter
)
120 static void SetGlobalConfig(const ScCalcConfig
& rConfig
);
121 static const ScCalcConfig
& GetGlobalConfig();
123 static void GlobalExit(); // called by ScGlobal::Clear()
125 /// Could string be a regular expression?
126 /// If pDoc!=NULL the document options are taken into account and if
127 /// RegularExpressions are disabled the function returns false regardless
128 /// of the string content.
129 static bool MayBeRegExp( const OUString
& rStr
, const ScDocument
* pDoc
);
131 /// Fail safe division, returning an errDivisionByZero coded into a double
132 /// if denominator is 0.0
133 static inline double div( const double& fNumerator
, const double& fDenominator
);
135 ScMatrixRef
GetNewMat(SCSIZE nC
, SCSIZE nR
, bool bEmpty
= false);
143 VolatileType
GetVolatileType() const;
146 static ScCalcConfig maGlobalConfig
;
148 static ScTokenStack
* pGlobalStack
;
149 static bool bGlobalStackInUse
;
151 formula::FormulaTokenIterator aCode
;
155 svl::SharedStringPool
& mrStrPool
;
156 formula::FormulaTokenRef xResult
;
157 ScJumpMatrix
* pJumpMatrix
; // currently active array condition, if any
158 ScTokenMatrixMap
* pTokenMatrixMap
; // map ScToken* to formula::FormulaTokenRef if in array condition
159 ScFormulaCell
* pMyFormulaCell
; // the cell of this formula expression
160 SvNumberFormatter
* pFormatter
;
162 const formula::FormulaToken
*
163 pCur
; // current token
164 ScTokenStack
* pStackObj
; // contains the stacks
165 formula::FormulaToken
** pStack
; // the current stack
166 sal_uInt16 nGlobalError
; // global (local to this formula expression) error
167 sal_uInt16 sp
; // stack pointer
168 sal_uInt16 maxsp
; // the maximal used stack pointer
169 sal_uLong nFuncFmtIndex
; // NumberFormatIndex of a function
170 sal_uLong nCurFmtIndex
; // current NumberFormatIndex
171 sal_uLong nRetFmtIndex
; // NumberFormatIndex of an expression, if any
172 short nFuncFmtType
; // NumberFormatType of a function
173 short nCurFmtType
; // current NumberFormatType
174 short nRetFmtType
; // NumberFormatType of an expression
175 sal_uInt16 mnStringNoValueError
; // the error set in ConvertStringToValue() if no value
176 bool glSubTotal
; // flag for subtotal functions
177 sal_uInt8 cPar
; // current count of parameters
178 bool bCalcAsShown
; // precision as shown
179 bool bMatrixFormula
; // formula cell is a matrix formula
181 VolatileType meVolatileType
;
183 // nMust <= nAct <= nMax ? ok : PushError
184 inline bool MustHaveParamCount( short nAct
, short nMust
);
185 inline bool MustHaveParamCount( short nAct
, short nMust
, short nMax
);
186 inline bool MustHaveParamCountMin( short nAct
, short nMin
);
187 void PushParameterExpected();
188 void PushIllegalParameter();
189 void PushIllegalArgument();
193 // Functions for accessing a document
195 void ReplaceCell( ScAddress
& ); // for TableOp
196 void ReplaceCell( SCCOL
& rCol
, SCROW
& rRow
, SCTAB
& rTab
); // for TableOp
197 bool IsTableOpInRange( const ScRange
& );
198 sal_uLong
GetCellNumberFormat( const ScAddress
& rPos
, ScRefCellValue
& rCell
);
199 double ConvertStringToValue( const OUString
& );
200 double GetCellValue( const ScAddress
&, ScRefCellValue
& rCell
);
201 double GetCellValueOrZero( const ScAddress
&, ScRefCellValue
& rCell
);
202 double GetValueCellValue( const ScAddress
&, double fOrig
);
203 void GetCellString( svl::SharedString
& rStr
, ScRefCellValue
& rCell
);
204 sal_uInt16
GetCellErrCode( const ScRefCellValue
& rCell
);
206 bool CreateDoubleArr(SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
207 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
, sal_uInt8
* pCellArr
);
208 bool CreateStringArr(SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
209 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
, sal_uInt8
* pCellArr
);
210 bool CreateCellArr(SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
211 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
, sal_uInt8
* pCellArr
);
215 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
216 passed is not formula::FormulaErrorToken.
217 Increments RefCount of the original token if not substituted. */
218 void Push( formula::FormulaToken
& r
);
220 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
221 Used to push RPN tokens or from within Push() or tokens that are already
222 explicit formula::FormulaErrorToken. Increments RefCount. */
223 void PushWithoutError( formula::FormulaToken
& r
);
225 /** Clones the token to be pushed or substitutes with formula::FormulaErrorToken if
226 nGlobalError is set and the token passed is not formula::FormulaErrorToken. */
227 void PushTempToken( const formula::FormulaToken
& );
229 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
230 passed is not formula::FormulaErrorToken.
231 Increments RefCount of the original token if not substituted.
232 ATTENTION! The token had to be allocated with `new' and must not be used
233 after this call if no RefCount was set because possibly it gets immediately
234 deleted in case of an errStackOverflow or if substituted with formula::FormulaErrorToken! */
235 void PushTempToken( formula::FormulaToken
* );
237 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
238 Used to push tokens from within PushTempToken() or tokens that are already
239 explicit formula::FormulaErrorToken. Increments RefCount.
240 ATTENTION! The token had to be allocated with `new' and must not be used
241 after this call if no RefCount was set because possibly it gets immediately
242 decremented again and thus deleted in case of an errStackOverflow! */
243 void PushTempTokenWithoutError( formula::FormulaToken
* );
245 /** If nGlobalError is set push formula::FormulaErrorToken.
246 If nGlobalError is not set do nothing.
247 Used in PushTempToken() and alike to simplify handling.
248 @return: <TRUE/> if nGlobalError. */
249 inline bool IfErrorPushError()
253 PushTempTokenWithoutError( new formula::FormulaErrorToken( nGlobalError
));
259 /** Obtain cell result / content from address and push as temp token.
260 bDisplayEmptyAsString is passed to ScEmptyCell in case of an empty cell
261 result. Also obtain number format and type if _both_, type and index
262 pointer, are not NULL. */
263 void PushCellResultToken( bool bDisplayEmptyAsString
, const ScAddress
& rAddress
,
264 short * pRetTypeExpr
, sal_uLong
* pRetIndexExpr
);
266 formula::FormulaTokenRef
PopToken();
270 svl::SharedString
PopString();
271 void ValidateRef( const ScSingleRefData
& rRef
);
272 void ValidateRef( const ScComplexRefData
& rRef
);
273 void ValidateRef( const ScRefList
& rRefList
);
274 void SingleRefToVars( const ScSingleRefData
& rRef
, SCCOL
& rCol
, SCROW
& rRow
, SCTAB
& rTab
);
275 void PopSingleRef( ScAddress
& );
276 void PopSingleRef(SCCOL
& rCol
, SCROW
&rRow
, SCTAB
& rTab
);
277 void DoubleRefToRange( const ScComplexRefData
&, ScRange
&, bool bDontCheckForTableOp
= false );
278 /** If formula::StackVar formula::svDoubleRef pop ScDoubleRefToken and return values of
280 Else if StackVar svRefList return values of the ScComplexRefData where
281 rRefInList is pointing to. rRefInList is incremented. If rRefInList was the
282 last element in list pop ScRefListToken and set rRefInList to 0, else
283 rParam is incremented (!) to allow usage as in
284 while(nParamCount--) PopDoubleRef(aRange,nParamCount,nRefInList);
286 void PopDoubleRef( ScRange
& rRange
, short & rParam
, size_t & rRefInList
);
287 void PopDoubleRef( ScRange
&, bool bDontCheckForTableOp
= false );
288 void DoubleRefToVars( const ScToken
* p
,
289 SCCOL
& rCol1
, SCROW
&rRow1
, SCTAB
& rTab1
,
290 SCCOL
& rCol2
, SCROW
&rRow2
, SCTAB
& rTab2
,
291 bool bDontCheckForTableOp
= false );
292 ScDBRangeBase
* PopDBDoubleRef();
293 void PopDoubleRef(SCCOL
& rCol1
, SCROW
&rRow1
, SCTAB
& rTab1
,
294 SCCOL
& rCol2
, SCROW
&rRow2
, SCTAB
& rTab2
,
295 bool bDontCheckForTableOp
= false );
296 void PopExternalSingleRef(sal_uInt16
& rFileId
, OUString
& rTabName
, ScSingleRefData
& rRef
);
297 void PopExternalSingleRef(ScExternalRefCache::TokenRef
& rToken
, ScExternalRefCache::CellFormat
* pFmt
= NULL
);
298 void PopExternalSingleRef(sal_uInt16
& rFileId
, OUString
& rTabName
, ScSingleRefData
& rRef
,
299 ScExternalRefCache::TokenRef
& rToken
, ScExternalRefCache::CellFormat
* pFmt
= NULL
);
300 void PopExternalDoubleRef(sal_uInt16
& rFileId
, OUString
& rTabName
, ScComplexRefData
& rRef
);
301 void PopExternalDoubleRef(ScExternalRefCache::TokenArrayRef
& rArray
);
302 void PopExternalDoubleRef(ScMatrixRef
& rMat
);
303 void GetExternalDoubleRef(sal_uInt16 nFileId
, const OUString
& rTabName
, const ScComplexRefData
& aData
, ScExternalRefCache::TokenArrayRef
& rArray
);
304 bool PopDoubleRefOrSingleRef( ScAddress
& rAdr
);
305 void PopDoubleRefPushMatrix();
306 // If MatrixFormula: convert formula::svDoubleRef to svMatrix, create JumpMatrix.
307 // Else convert area reference parameters marked as ForceArray to array.
308 // Returns true if JumpMatrix created.
309 bool ConvertMatrixParameters();
310 inline void MatrixDoubleRefToMatrix(); // if MatrixFormula: PopDoubleRefPushMatrix
311 // If MatrixFormula or ForceArray: ConvertMatrixParameters()
312 inline bool MatrixParameterConversion();
313 ScMatrixRef
PopMatrix();
314 sc::RangeMatrix
PopRangeMatrix();
315 void QueryMatrixType(ScMatrixRef
& xMat
, short& rRetTypeExpr
, sal_uLong
& rRetIndexExpr
);
317 void PushDouble(double nVal
);
318 void PushInt( int nVal
);
319 void PushStringBuffer( const sal_Unicode
* pString
);
320 void PushString( const OUString
& rStr
);
321 void PushString( const svl::SharedString
& rString
);
322 void PushSingleRef(SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
323 void PushDoubleRef(SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
324 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
);
325 void PushExternalSingleRef(sal_uInt16 nFileId
, const OUString
& rTabName
,
326 SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
327 void PushExternalDoubleRef(sal_uInt16 nFileId
, const OUString
& rTabName
,
328 SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
329 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
);
330 void PushMatrix( const sc::RangeMatrix
& rMat
);
331 void PushMatrix(const ScMatrixRef
& pMat
);
332 void PushError( sal_uInt16 nError
);
333 /// Raw stack type without default replacements.
334 formula::StackVar
GetRawStackType();
335 /// Stack type with replacement of defaults, e.g. svMissing and formula::svEmptyCell will result in formula::svDouble.
336 formula::StackVar
GetStackType();
337 // peek StackType of Parameter, Parameter 1 == TOS, 2 == TOS-1, ...
338 formula::StackVar
GetStackType( sal_uInt8 nParam
);
339 sal_uInt8
GetByte() { return cPar
; }
340 // generates a position-dependent SingleRef out of a DoubleRef
341 bool DoubleRefToPosSingleRef( const ScRange
& rRange
, ScAddress
& rAdr
);
342 double GetDoubleFromMatrix(const ScMatrixRef
& pMat
);
344 double GetDoubleWithDefault(double nDefault
);
346 bool GetBool() { return GetDouble() != 0.0; }
347 svl::SharedString
GetString();
348 svl::SharedString
GetStringFromMatrix(const ScMatrixRef
& pMat
);
349 // pop matrix and obtain one element, upper left or according to jump matrix
350 ScMatValType
GetDoubleOrStringFromMatrix( double& rDouble
, svl::SharedString
& rString
);
351 ScMatrixRef
CreateMatrixFromDoubleRef( const formula::FormulaToken
* pToken
,
352 SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
353 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
);
354 inline ScTokenMatrixMap
& GetTokenMatrixMap();
355 ScTokenMatrixMap
* CreateTokenMatrixMap();
356 ScMatrixRef
GetMatrix();
357 sc::RangeMatrix
GetRangeMatrix();
359 void ScTableOp(); // repeated operations
360 void ScErrCell(); // special handling for
363 // common helper functions
365 void SetMaxIterationCount(sal_uInt16 n
);
366 inline void CurFmtToFuncFmt()
367 { nFuncFmtType
= nCurFmtType
; nFuncFmtIndex
= nCurFmtIndex
; }
368 // Check for String overflow of rResult+rAdd and set error and erase rResult
369 // if so. Return true if ok, false if overflow
370 inline bool CheckStringResultLen( OUString
& rResult
, const OUString
& rAdd
);
371 // Set error according to rVal, and set rVal to 0.0 if there was an error.
372 inline void TreatDoubleError( double& rVal
);
373 // Lookup using ScLookupCache, @returns true if found and result address
374 bool LookupQueryWithCache( ScAddress
& o_rResultPos
,
375 const ScQueryParam
& rParam
) const;
378 void ScIfError( bool bNAonly
);
381 // Be sure to only call this if pStack[sp-nStackLevel] really contains a
382 // ScJumpMatrixToken, no further checks are applied!
383 // Returns true if last jump was executed and result matrix pushed.
384 bool JumpMatrix( short nStackLevel
);
388 NULL means case sensitivity document option is to be used!
390 sc::RangeMatrix
CompareMat( ScQueryOp eOp
, sc::CompareOptions
* pOptions
= NULL
);
391 ScMatrixRef
QueryMat( const ScMatrixRef
& pMat
, sc::CompareOptions
& rOptions
);
397 void ScGreaterEqual();
403 void ScPercentSign();
431 void ScCosecantHyp();
440 void ScIsNonString();
444 void ScCellExternal();
466 void ScNumberValue();
473 void ScMin( bool bTextAsZero
= false );
474 void ScMax( bool bTextAsZero
= false );
475 double IterateParameters( ScIterFunc
, bool bTextAsZero
= false );
479 void ScAverage( bool bTextAsZero
= false );
482 void GetStVarParams( double& rVal
, double& rValCount
, bool bTextAsZero
= false );
483 void ScVar( bool bTextAsZero
= false );
484 void ScVarP( bool bTextAsZero
= false );
485 void ScStDev( bool bTextAsZero
= false );
486 void ScStDevP( bool bTextAsZero
= false );
494 double IterateParametersIf( ScIterFuncIf
);
498 double IterateParametersIfs( ScIterFuncIfs
);
502 void ScCountEmptyCells();
508 // If upon call rMissingField==true then the database field parameter may be
509 // missing (Xcl DCOUNT() syntax), or may be faked as missing by having the
510 // value 0.0 or being exactly the entire database range reference (old SO
511 // compatibility). If this was the case then rMissingField is set to true upon
512 // return. If rMissingField==false upon call all "missing cases" are considered
514 ScDBQueryParamBase
* GetDBParams( bool& rMissingField
);
516 void DBIterator( ScIterFunc
);
525 void GetDBStVarParams( double& rVal
, double& rValCount
);
531 void ScAddressFunc();
552 bool SetSbxVariable( SbxVariable
* pVar
, const ScAddress
& );
553 bool SetSbxVariable( SbxVariable
* pVar
, SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
556 void ScColRowNameAuto();
557 void ScGetPivotData();
568 /** Obtain the date serial number for a given date.
570 If false, nYear < 100 takes the two-digit year setting into account,
571 and rollover of invalid calendar dates takes place, e.g. 1999-02-31 =>
573 If true, the date passed must be a valid Gregorian calendar date. No
574 two-digit expanding or rollover is done.
576 @param bCheckGregorian
577 If true, date must be Gregorian, i.e. >= 1582-10-15.
578 If false, don't care, any valid date >= 0-1-1 will do.
580 double GetDateSerial( sal_Int16 nYear
, sal_Int16 nMonth
, sal_Int16 nDay
, bool bStrict
, bool bCheckGregorian
);
587 void ScGetDayOfWeek();
588 void ScGetWeekOfYear();
589 void ScEasterSunday();
600 void RoundNumber( rtl_math_RoundingMode eMode
);
604 void ScGetDateValue();
605 void ScGetTimeValue();
610 void ScGetDiffDate();
611 void ScGetDiffDate360();
626 void ScEuroConvert();
628 // financial functions
634 double ScGetBw(double fZins
, double fZzr
, double fRmz
,
635 double fZw
, double fF
);
638 double ScGetGDA(double fWert
, double fRest
, double fDauer
,
639 double fPeriode
, double fFactor
);
642 double ScInterVDB(double fWert
,double fRest
,double fDauer
,double fDauer1
,
643 double fPeriode
,double fFactor
);
647 double ScGetRmz(double fZins
, double fZzr
, double fBw
,
648 double fZw
, double fF
);
651 double ScGetZw(double fZins
, double fZzr
, double fRmz
,
652 double fBw
, double fF
);
655 bool RateIteration(double fNper
, double fPayment
, double fPv
,
656 double fFv
, double fPayType
, double& fGuess
);
658 double ScGetZinsZ(double fZins
, double fZr
, double fZzr
, double fBw
,
659 double fZw
, double fF
, double& fRmz
);
668 double ScGetGCD(double fx
, double fy
);
674 void MEMat(const ScMatrixRef
& mM
, SCSIZE n
);
681 ScMatrixRef
MatConcat(const ScMatrixRef
& pMat1
, const ScMatrixRef
& pMat2
);
687 bool CalculateSkew(double& fSum
,double& fCount
,double& vSum
,std::vector
<double>& values
);
688 void CalculateSkewOrSkewp( bool bSkewp
);
689 void CalculateSlopeIntercept(bool bSlope
);
690 void CalculateSmallLarge(bool bSmall
);
691 void CalculatePearsonCovar( bool _bPearson
, bool _bStexy
, bool _bSample
); //fdo#70000 argument _bSample is ignored if _bPearson == true
692 bool CalculateTest( bool _bTemplin
693 ,const SCSIZE nC1
, const SCSIZE nC2
,const SCSIZE nR1
,const SCSIZE nR2
694 ,const ScMatrixRef
& pMat1
,const ScMatrixRef
& pMat2
695 ,double& fT
,double& fF
);
696 void CalculateLookup(bool bHLookup
);
697 bool FillEntry(ScQueryEntry
& rEntry
);
698 void CalculateAddSub(bool _bSub
);
699 void CalculateTrendGrowth(bool _bGrowth
);
700 void CalulateRGPRKP(bool _bRKP
);
701 void CalculateSumX2MY2SumX2DY2(bool _bSumX2DY2
);
702 void CalculateMatrixValue(const ScMatrix
* pMat
,SCSIZE nC
,SCSIZE nR
);
703 bool CheckMatrix(bool _bLOG
,sal_uInt8
& nCase
,SCSIZE
& nCX
,SCSIZE
& nCY
,SCSIZE
& nRX
,SCSIZE
& nRY
,SCSIZE
& M
,SCSIZE
& N
,ScMatrixRef
& pMatX
,ScMatrixRef
& pMatY
);
710 double phi(double x
);
711 double integralPhi(double x
);
712 double taylor(double* pPolynom
, sal_uInt16 nMax
, double x
);
713 double gauss(double x
);
714 double gaussinv(double x
);
715 double GetBetaDist(double x
, double alpha
, double beta
); //cumulative distribution function
716 double GetBetaDistPDF(double fX
, double fA
, double fB
); //probability density function)
717 double GetChiDist(double fChi
, double fDF
); // for LEGACY.CHIDIST, returns right tail
718 double GetChiSqDistCDF(double fX
, double fDF
); // for CHISQDIST, returns left tail
719 double GetChiSqDistPDF(double fX
, double fDF
); // probability density function
720 double GetFDist(double x
, double fF1
, double fF2
);
721 double GetTDist(double T
, double fDF
);
722 double Fakultaet(double x
);
723 double BinomKoeff(double n
, double k
);
724 double GetGamma(double x
);
725 double GetLogGamma(double x
);
726 double GetBeta(double fAlpha
, double fBeta
);
727 double GetLogBeta(double fAlpha
, double fBeta
);
728 double GetBinomDistPMF(double x
, double n
, double p
); //probability mass function
729 double GetHypGeomDist( double x
, double n
, double M
, double N
);
734 void ScStdNormDist();
743 void ScPoissonDist();
746 void ScVariationen();
747 void ScVariationen2();
749 void ScHypGeomDist();
750 void ScHypGeomDist_MS();
751 void ScLogNormDist();
756 void ScChiDist(); // for LEGACY.CHIDIST, returns right tail
757 void ScChiSqDist(); // returns left tail or density
758 void ScChiSqDist_MS();
759 void ScChiSqInv(); //invers to CHISQDIST
762 void ScBetaDist_MS();
769 void ScNegBinomDist();
777 double GetMedian( ::std::vector
<double> & rArray
);
778 double GetPercentile( ::std::vector
<double> & rArray
, double fPercentile
);
779 void GetNumberSequenceArray( sal_uInt8 nParamCount
, ::std::vector
<double>& rArray
);
780 void GetSortArray(sal_uInt8 nParamCount
, ::std::vector
<double>& rSortArray
, ::std::vector
<long>* pIndexOrder
= NULL
);
781 void QuickSort(::std::vector
<double>& rSortArray
, ::std::vector
<long>* pIndexOrder
= NULL
);
791 void ScPercentrank();
799 void ScConfidenceT();
801 void ScProbability();
803 void ScCovarianceP();
804 void ScCovarianceS();
819 static const double fMaxGammaArgument
;
821 double GetGammaContFraction(double fA
,double fX
);
822 double GetGammaSeries(double fA
,double fX
);
823 double GetLowRegIGamma(double fA
,double fX
); // lower regularized incomplete gamma function, GAMMAQ
824 double GetUpRegIGamma(double fA
,double fX
); // upper regularized incomplete gamma function, GAMMAP
825 // probability density function; fLambda is "scale" parameter
826 double GetGammaDistPDF(double fX
, double fAlpha
, double fLambda
);
827 // cumulative distribution function; fLambda is "scale" parameter
828 double GetGammaDist(double fX
, double fAlpha
, double fLambda
);
829 double GetTInv( double fAlpha
, double fSize
);
832 ScInterpreter( ScFormulaCell
* pCell
, ScDocument
* pDoc
,
833 const ScAddress
&, ScTokenArray
& );
836 formula::StackVar
Interpret();
838 void SetError(sal_uInt16 nError
)
839 { if (nError
&& !nGlobalError
) nGlobalError
= nError
; }
841 sal_uInt16
GetError() const { return nGlobalError
; }
842 formula::StackVar
GetResultType() const { return xResult
->GetType(); }
843 svl::SharedString
GetStringResult() const;
844 double GetNumResult() const { return xResult
->GetDouble(); }
845 formula::FormulaTokenRef
GetResultToken() const { return xResult
; }
846 short GetRetFormatType() const { return nRetFmtType
; }
847 sal_uLong
GetRetFormatIndex() const { return nRetFmtIndex
; }
850 inline void ScInterpreter::MatrixDoubleRefToMatrix()
852 if ( bMatrixFormula
&& GetStackType() == formula::svDoubleRef
)
854 GetTokenMatrixMap(); // make sure it exists, create if not.
855 PopDoubleRefPushMatrix();
859 inline bool ScInterpreter::MatrixParameterConversion()
861 if ( (bMatrixFormula
|| pCur
->HasForceArray()) && !pJumpMatrix
&& sp
> 0 )
862 return ConvertMatrixParameters();
866 inline ScTokenMatrixMap
& ScInterpreter::GetTokenMatrixMap()
868 if (!pTokenMatrixMap
)
869 pTokenMatrixMap
= CreateTokenMatrixMap();
870 return *pTokenMatrixMap
;
873 inline bool ScInterpreter::MustHaveParamCount( short nAct
, short nMust
)
878 PushParameterExpected();
880 PushIllegalParameter();
884 inline bool ScInterpreter::MustHaveParamCount( short nAct
, short nMust
, short nMax
)
886 if ( nMust
<= nAct
&& nAct
<= nMax
)
889 PushParameterExpected();
891 PushIllegalParameter();
895 inline bool ScInterpreter::MustHaveParamCountMin( short nAct
, short nMin
)
899 PushParameterExpected();
903 inline bool ScInterpreter::CheckStringResultLen( OUString
& rResult
, const OUString
& rAdd
)
905 if ( (sal_uLong
) rResult
.getLength() + rAdd
.getLength() > STRING_MAXLEN
)
907 SetError( errStringOverflow
);
914 inline void ScInterpreter::TreatDoubleError( double& rVal
)
916 if ( !::rtl::math::isFinite( rVal
) )
918 sal_uInt16 nErr
= GetDoubleErrorValue( rVal
);
922 SetError( errNoValue
);
927 inline double ScInterpreter::div( const double& fNumerator
, const double& fDenominator
)
929 return (fDenominator
!= 0.0) ? (fNumerator
/ fDenominator
) :
930 CreateDoubleError( errDivisionByZero
);
935 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */