1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: interpre.hxx,v $
10 * $Revision: 1.35.44.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_INTERPRE_HXX
32 #define SC_INTERPRE_HXX
34 #define SC_SPEW_ENABLED 0
37 #include <rtl/math.hxx>
38 #include "formula/errorcodes.hxx"
41 #include "document.hxx"
42 #include "scmatrix.hxx"
55 class SvNumberFormatter
;
57 struct MatrixDoubleOp
;
59 struct ScDBQueryParamBase
;
67 ScCompare( String
* p1
, String
* p2
)
76 struct ScCompareOptions
78 ScQueryEntry aQueryEntry
;
83 ScCompareOptions( ScDocument
* pDoc
, const ScQueryEntry
& rEntry
, bool bReg
);
85 // Not implemented, prevent usage.
87 ScCompareOptions( const ScCompareOptions
& );
88 ScCompareOptions
& operator=( const ScCompareOptions
& );
93 #define MAXSTACK (4096 / sizeof(formula::FormulaToken*))
98 DECL_FIXEDMEMPOOL_NEWDEL( ScTokenStack
)
99 formula::FormulaToken
* pPointer
[ MAXSTACK
];
103 ifSUM
, // Aufsummieren
104 ifSUMSQ
, // Quadratsummen
105 ifPRODUCT
, // Multiplizieren
106 ifAVERAGE
, // Durchschnitt
107 ifCOUNT
, // Anzahl Werte
108 ifCOUNT2
, // Anzahl Werte (nichtleer)
113 struct FormulaTokenRef_less
115 bool operator () ( const formula::FormulaConstTokenRef
& r1
, const formula::FormulaConstTokenRef
& r2
) const
116 { return &r1
< &r2
; }
118 typedef ::std::map
< const formula::FormulaConstTokenRef
, formula::FormulaTokenRef
, FormulaTokenRef_less
> ScTokenMatrixMap
;
122 // distibution function objects need the GetxxxDist methods
123 friend class ScGammaDistFunction
;
124 friend class ScBetaDistFunction
;
125 friend class ScTDistFunction
;
126 friend class ScFDistFunction
;
127 friend class ScChiDistFunction
;
128 friend class ScChiSqDistFunction
;
131 DECL_FIXEDMEMPOOL_NEWDEL( ScInterpreter
)
133 static ScSpew theSpew
;
136 static void GlobalExit(); // aus ScGlobal::Clear() gerufen
138 /// Could string be a regular expression?
139 /// If pDoc!=NULL the document options are taken into account and if
140 /// RegularExpressions are disabled the function returns FALSE regardless
141 /// of the string content.
142 static BOOL
MayBeRegExp( const String
& rStr
, const ScDocument
* pDoc
);
144 /// Fail safe division, returning an errDivisionByZero coded into a double
145 /// if denominator is 0.0
146 static inline double div( const double& fNumerator
, const double& fDenominator
);
148 ScMatrixRef
GetNewMat(SCSIZE nC
, SCSIZE nR
);
156 VolatileType
GetVolatileType() const;
159 static ScTokenStack
* pGlobalStack
;
160 static BOOL bGlobalStackInUse
;
162 formula::FormulaTokenIterator aCode
;
166 formula::FormulaTokenRef xResult
;
167 ScJumpMatrix
* pJumpMatrix
; // currently active array condition, if any
168 ScTokenMatrixMap
* pTokenMatrixMap
; // map ScToken* to formula::FormulaTokenRef if in array condition
169 ScFormulaCell
* pMyFormulaCell
; // the cell of this formula expression
170 SvNumberFormatter
* pFormatter
;
172 const formula::FormulaToken
*
173 pCur
; // current token
174 String aTempStr
; // for GetString()
175 ScTokenStack
* pStackObj
; // contains the stacks
176 formula::FormulaToken
** pStack
; // the current stack
177 USHORT nGlobalError
; // global (local to this formula expression) error
178 USHORT sp
; // stack pointer
179 USHORT maxsp
; // the maximal used stack pointer
180 ULONG nFuncFmtIndex
; // NumberFormatIndex of a function
181 ULONG nCurFmtIndex
; // current NumberFormatIndex
182 ULONG nRetFmtIndex
; // NumberFormatIndex of an expression, if any
183 short nFuncFmtType
; // NumberFormatType of a function
184 short nCurFmtType
; // current NumberFormatType
185 short nRetFmtType
; // NumberFormatType of an expression
186 BOOL glSubTotal
; // flag for subtotal functions
187 BYTE cPar
; // current count of parameters
188 BOOL bCalcAsShown
; // precision as shown
189 BOOL bMatrixFormula
; // formula cell is a matrix formula
191 VolatileType meVolaileType
;
193 //---------------------------------Funktionen in interpre.cxx---------
194 // nMust <= nAct <= nMax ? ok : PushError
195 inline BOOL
MustHaveParamCount( short nAct
, short nMust
);
196 inline BOOL
MustHaveParamCount( short nAct
, short nMust
, short nMax
);
197 inline BOOL
MustHaveParamCountMin( short nAct
, short nMin
);
198 void PushParameterExpected();
199 void PushIllegalParameter();
200 void PushIllegalArgument();
203 //-------------------------------------------------------------------------
204 // Funktionen fuer den Zugriff auf das Document
205 //-------------------------------------------------------------------------
206 void ReplaceCell( ScAddress
& ); // for TableOp
207 void ReplaceCell( SCCOL
& rCol
, SCROW
& rRow
, SCTAB
& rTab
); // for TableOp
208 BOOL
IsTableOpInRange( const ScRange
& );
209 ULONG
GetCellNumberFormat( const ScAddress
&, const ScBaseCell
* );
210 double ConvertStringToValue( const String
& );
211 double GetCellValue( const ScAddress
&, const ScBaseCell
* );
212 double GetCellValueOrZero( const ScAddress
&, const ScBaseCell
* );
213 double GetValueCellValue( const ScAddress
&, const ScValueCell
* );
214 ScBaseCell
* GetCell( const ScAddress
& rPos
)
215 { return pDok
->GetCell( rPos
); }
216 void GetCellString( String
& rStr
, const ScBaseCell
* pCell
);
217 inline USHORT
GetCellErrCode( const ScBaseCell
* pCell
)
218 { return pCell
? pCell
->GetErrorCode() : 0; }
219 inline CellType
GetCellType( const ScBaseCell
* pCell
)
220 { return pCell
? pCell
->GetCellType() : CELLTYPE_NONE
; }
221 /// Really empty or inherited emptiness.
222 inline BOOL
HasCellEmptyData( const ScBaseCell
* pCell
)
223 { return pCell
? pCell
->HasEmptyData() : TRUE
; }
224 /// This includes inherited emptiness, which usually is regarded as value!
225 inline BOOL
HasCellValueData( const ScBaseCell
* pCell
)
226 { return pCell
? pCell
->HasValueData() : FALSE
; }
227 /// Not empty and not value.
228 inline BOOL
HasCellStringData( const ScBaseCell
* pCell
)
229 { return pCell
? pCell
->HasStringData() : FALSE
; }
231 BOOL
CreateDoubleArr(SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
232 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
, BYTE
* pCellArr
);
233 BOOL
CreateStringArr(SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
234 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
, BYTE
* pCellArr
);
235 BOOL
CreateCellArr(SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
236 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
, BYTE
* pCellArr
);
238 //-----------------------------------------------------------------------------
240 //-----------------------------------------------------------------------------
242 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
243 passed is not formula::FormulaErrorToken.
244 Increments RefCount of the original token if not substituted. */
245 void Push( formula::FormulaToken
& r
);
247 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
248 Used to push RPN tokens or from within Push() or tokens that are already
249 explicit formula::FormulaErrorToken. Increments RefCount. */
250 void PushWithoutError( formula::FormulaToken
& r
);
252 /** Clones the token to be pushed or substitutes with formula::FormulaErrorToken if
253 nGlobalError is set and the token passed is not formula::FormulaErrorToken. */
254 void PushTempToken( const formula::FormulaToken
& );
256 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
257 passed is not formula::FormulaErrorToken.
258 Increments RefCount of the original token if not substituted.
259 ATTENTION! The token had to be allocated with `new' and must not be used
260 after this call if no RefCount was set because possibly it gets immediately
261 deleted in case of an errStackOverflow or if substituted with formula::FormulaErrorToken! */
262 void PushTempToken( formula::FormulaToken
* );
264 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
265 Used to push tokens from within PushTempToken() or tokens that are already
266 explicit formula::FormulaErrorToken. Increments RefCount.
267 ATTENTION! The token had to be allocated with `new' and must not be used
268 after this call if no RefCount was set because possibly it gets immediately
269 decremented again and thus deleted in case of an errStackOverflow! */
270 void PushTempTokenWithoutError( formula::FormulaToken
* );
272 /** If nGlobalError is set push formula::FormulaErrorToken.
273 If nGlobalError is not set do nothing.
274 Used in PushTempToken() and alike to simplify handling.
275 @return: <TRUE/> if nGlobalError. */
276 inline bool IfErrorPushError()
280 PushTempTokenWithoutError( new formula::FormulaErrorToken( nGlobalError
));
286 /** Obtain cell result / content from address and push as temp token.
287 bDisplayEmptyAsString is passed to ScEmptyCell in case of an empty cell
288 result. Also obtain number format and type if _both_, type and index
289 pointer, are not NULL. */
290 void PushCellResultToken( bool bDisplayEmptyAsString
, const ScAddress
& rAddress
,
291 short * pRetTypeExpr
, ULONG
* pRetIndexExpr
);
293 formula::FormulaTokenRef
PopToken();
297 const String
& PopString();
298 void ValidateRef( const ScSingleRefData
& rRef
);
299 void ValidateRef( const ScComplexRefData
& rRef
);
300 void ValidateRef( const ScRefList
& rRefList
);
301 void SingleRefToVars( const ScSingleRefData
& rRef
, SCCOL
& rCol
, SCROW
& rRow
, SCTAB
& rTab
);
302 void PopSingleRef( ScAddress
& );
303 void PopSingleRef(SCCOL
& rCol
, SCROW
&rRow
, SCTAB
& rTab
);
304 void DoubleRefToRange( const ScComplexRefData
&, ScRange
&, BOOL bDontCheckForTableOp
= FALSE
);
305 /** If formula::StackVar formula::svDoubleRef pop ScDoubleRefToken and return values of
307 Else if StackVar svRefList return values of the ScComplexRefData where
308 rRefInList is pointing to. rRefInList is incremented. If rRefInList was the
309 last element in list pop ScRefListToken and set rRefInList to 0, else
310 rParam is incremented (!) to allow usage as in
311 while(nParamCount--) PopDoubleRef(aRange,nParamCount,nRefInList);
313 void PopDoubleRef( ScRange
& rRange
, short & rParam
, size_t & rRefInList
);
314 void PopDoubleRef( ScRange
&, BOOL bDontCheckForTableOp
= FALSE
);
315 void DoubleRefToVars( const ScToken
* p
,
316 SCCOL
& rCol1
, SCROW
&rRow1
, SCTAB
& rTab1
,
317 SCCOL
& rCol2
, SCROW
&rRow2
, SCTAB
& rTab2
,
318 BOOL bDontCheckForTableOp
= FALSE
);
319 ScDBRangeBase
* PopDoubleRef();
320 void PopDoubleRef(SCCOL
& rCol1
, SCROW
&rRow1
, SCTAB
& rTab1
,
321 SCCOL
& rCol2
, SCROW
&rRow2
, SCTAB
& rTab2
,
322 BOOL bDontCheckForTableOp
= FALSE
);
323 BOOL
PopDoubleRefOrSingleRef( ScAddress
& rAdr
);
324 void PopDoubleRefPushMatrix();
325 // If MatrixFormula: convert formula::svDoubleRef to svMatrix, create JumpMatrix.
326 // Else convert area reference parameters marked as ForceArray to array.
327 // Returns TRUE if JumpMatrix created.
328 bool ConvertMatrixParameters();
329 inline void MatrixDoubleRefToMatrix(); // if MatrixFormula: PopDoubleRefPushMatrix
330 // If MatrixFormula or ForceArray: ConvertMatrixParameters()
331 inline bool MatrixParameterConversion();
332 ScMatrixRef
PopMatrix();
333 //void PushByte(BYTE nVal);
334 void PushDouble(double nVal
);
335 void PushInt( int nVal
);
336 void PushStringBuffer( const sal_Unicode
* pString
);
337 void PushString( const String
& rString
);
338 void PushSingleRef(SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
339 void PushDoubleRef(SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
340 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
);
341 void PushMatrix(ScMatrix
* pMat
);
342 void PushError( USHORT nError
);
343 /// Raw stack type without default replacements.
344 formula::StackVar
GetRawStackType();
345 /// Stack type with replacement of defaults, e.g. svMissing and formula::svEmptyCell will result in formula::svDouble.
346 formula::StackVar
GetStackType();
347 // peek StackType of Parameter, Parameter 1 == TOS, 2 == TOS-1, ...
348 formula::StackVar
GetStackType( BYTE nParam
);
349 BYTE
GetByte() { return cPar
; }
350 // generiert aus DoubleRef positionsabhaengige SingleRef
351 BOOL
DoubleRefToPosSingleRef( const ScRange
& rRange
, ScAddress
& rAdr
);
353 double GetDoubleWithDefault(double nDefault
);
355 BOOL
GetBool() { return GetDouble() != 0.0; }
356 const String
& GetString();
357 // pop matrix and obtain one element, upper left or according to jump matrix
358 ScMatValType
GetDoubleOrStringFromMatrix( double& rDouble
, String
& rString
);
359 ScMatrixRef
CreateMatrixFromDoubleRef( const formula::FormulaToken
* pToken
,
360 SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
361 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
);
362 inline ScTokenMatrixMap
& GetTokenMatrixMap();
363 ScTokenMatrixMap
* CreateTokenMatrixMap();
364 ScMatrixRef
GetMatrix();
365 void ScTableOp(); // Mehrfachoperationen
366 void ScErrCell(); // Sonderbehandlung
368 //-----------------------------allgemeine Hilfsfunktionen
369 void SetMaxIterationCount(USHORT n
);
370 inline void CurFmtToFuncFmt()
371 { nFuncFmtType
= nCurFmtType
; nFuncFmtIndex
= nCurFmtIndex
; }
372 // Check for String overflow of rResult+rAdd and set error and erase rResult
373 // if so. Return TRUE if ok, FALSE if overflow
374 inline BOOL
CheckStringResultLen( String
& rResult
, const String
& rAdd
);
375 // Set error according to rVal, and set rVal to 0.0 if there was an error.
376 inline void TreatDoubleError( double& rVal
);
377 // Lookup using ScLookupCache, @returns TRUE if found and result address
378 bool LookupQueryWithCache( ScAddress
& o_rResultPos
,
379 const ScQueryParam
& rParam
) const;
381 //---------------------------------Funktionen in interpr1.cxx---------
385 // Be sure to only call this if pStack[sp-nStackLevel] really contains a
386 // ScJumpMatrixToken, no further checks are applied!
387 // Returns true if last jump was executed and result matrix pushed.
388 bool JumpMatrix( short nStackLevel
);
391 NULL means case sensitivity document option is to be used!
393 double CompareFunc( const ScCompare
& rComp
, ScCompareOptions
* pOptions
= NULL
);
396 NULL means case sensitivity document option is to be used!
398 ScMatrixRef
CompareMat( ScCompareOptions
* pOptions
= NULL
);
399 ScMatrixRef
QueryMat( ScMatrix
* pMat
, ScCompareOptions
& rOptions
);
405 void ScGreaterEqual();
410 void ScPercentSign();
443 void ScIsNonString();
474 void ScMin( BOOL bTextAsZero
= FALSE
);
475 void ScMax( BOOL bTextAsZero
= FALSE
);
476 double IterateParameters( ScIterFunc
, BOOL bTextAsZero
= FALSE
);
480 void ScAverage( BOOL bTextAsZero
= FALSE
);
483 void GetStVarParams( double& rVal
, double& rValCount
, BOOL bTextAsZero
= FALSE
);
484 void ScVar( BOOL bTextAsZero
= FALSE
);
485 void ScVarP( BOOL bTextAsZero
= FALSE
);
486 void ScStDev( BOOL bTextAsZero
= FALSE
);
487 void ScStDevP( BOOL bTextAsZero
= FALSE
);
497 void ScCountEmptyCells();
503 // If upon call rMissingField==TRUE then the database field parameter may be
504 // missing (Xcl DCOUNT() syntax), or may be faked as missing by having the
505 // value 0.0 or being exactly the entire database range reference (old SO
506 // compatibility). If this was the case then rMissingField is set to TRUE upon
507 // return. If rMissingField==FALSE upon call all "missing cases" are considered
509 ScDBQueryParamBase
* GetDBParams( BOOL
& rMissingField
);
511 void DBIterator( ScIterFunc
);
520 void GetDBStVarParams( double& rVal
, double& rValCount
);
526 void ScAddressFunc();
547 BOOL
SetSbxVariable( SbxVariable
* pVar
, const ScAddress
& );
548 BOOL
SetSbxVariable( SbxVariable
* pVar
, SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
551 void ScColRowNameAuto();
552 void ScExternalRef();
553 void ScGetPivotData();
562 //----------------Funktionen in interpr2.cxx---------------
564 /** Obtain the date serial number for a given date.
566 If FALSE, nYear < 100 takes the two-digit year setting into account,
567 and rollover of invalid calendar dates takes place, e.g. 1999-02-31 =>
569 If TRUE, the date passed must be a valid Gregorian calendar date. No
570 two-digit expanding or rollover is done.
572 double GetDateSerial( INT16 nYear
, INT16 nMonth
, INT16 nDay
, bool bStrict
);
579 void ScGetDayOfWeek();
580 void ScGetWeekOfYear();
581 void ScEasterSunday();
592 void RoundNumber( rtl_math_RoundingMode eMode
);
596 void ScGetDateValue();
597 void ScGetTimeValue();
602 void ScGetDiffDate();
603 void ScGetDiffDate360();
617 void ScEuroConvert();
619 //----------------------- Finanzfunktionen ------------------------------------
625 double ScGetBw(double fZins
, double fZzr
, double fRmz
,
626 double fZw
, double fF
);
629 double ScGetGDA(double fWert
, double fRest
, double fDauer
,
630 double fPeriode
, double fFaktor
);
633 double ScInterVDB(double fWert
,double fRest
,double fDauer
,double fDauer1
,
634 double fPeriode
,double fFaktor
);
638 double ScGetRmz(double fZins
, double fZzr
, double fBw
,
639 double fZw
, double fF
);
642 double ScGetZw(double fZins
, double fZzr
, double fRmz
,
643 double fBw
, double fF
);
646 bool RateIteration(double fNper
, double fPayment
, double fPv
,
647 double fFv
, double fPayType
, double& fGuess
);
649 double ScGetZinsZ(double fZins
, double fZr
, double fZzr
, double fBw
,
650 double fZw
, double fF
, double& fRmz
);
660 //-------------------------Funktionen in interpr5.cxx--------------------------
661 double ScGetGCD(double fx
, double fy
);
664 //-------------------------- Matrixfunktionen ---------------------------------
667 void MEMat(ScMatrix
* mM
, SCSIZE n
);
668 void MFastMult(ScMatrix
* pA
, ScMatrix
* pB
, ScMatrix
* pR
, SCSIZE n
, SCSIZE m
, SCSIZE l
);
675 ScMatrixRef
MatConcat(ScMatrix
* pMat1
, ScMatrix
* pMat2
);
681 // multiple Regression: Varianzen der Koeffizienten
682 BOOL
RGetVariances( ScMatrix
* pV
, ScMatrix
* pX
, SCSIZE nC
, SCSIZE nR
,
683 BOOL bSwapColRow
, BOOL bZeroConstant
);
684 void Calculate(ScMatrixRef
& pResMat
,ScMatrixRef
& pE
,ScMatrixRef
& pQ
,ScMatrixRef
& pV
,ScMatrixRef
& pMatX
,BOOL bConstant
,SCSIZE N
,SCSIZE M
,BYTE nCase
);
685 ScMatrixRef
Calculate2(const BOOL bConstant
,const SCSIZE M
,const SCSIZE N
,ScMatrixRef
& pMatX
,ScMatrixRef
& pMatY
,BYTE nCase
);
686 bool Calculate3(const SCSIZE M
,ScMatrixRef
& pQ
);
687 bool Calculate4(BOOL _bExp
,ScMatrixRef
& pResMat
,ScMatrixRef
& pQ
,BOOL bConstant
,SCSIZE N
,SCSIZE M
);
688 bool CalculateSkew(double& fSum
,double& fCount
,double& vSum
,std::vector
<double>& values
);
689 void CalculateSlopeIntercept(BOOL bSlope
);
690 void CalculateSmallLarge(BOOL bSmall
);
691 void CalculatePearsonCovar(BOOL _bPearson
,BOOL _bStexy
);
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 HLookup
);
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
,BOOL _bTrendGrowth
,BYTE
& nCase
,SCSIZE
& nCX
,SCSIZE
& nCY
,SCSIZE
& nRX
,SCSIZE
& nRY
,SCSIZE
& M
,SCSIZE
& N
,ScMatrixRef
& pMatX
,ScMatrixRef
& pMatY
);
708 //------------------------- Functions in interpr3.cxx -------------------------
712 double phi(double x
);
713 double integralPhi(double x
);
714 double taylor(double* pPolynom
, USHORT nMax
, double x
);
715 double gauss(double x
);
716 double gaussinv(double x
);
717 double GetBetaDist(double x
, double alpha
, double beta
); //cumulative distribution function
718 double GetBetaDistPDF(double fX
, double fA
, double fB
); //probability density function)
719 double GetChiDist(double fChi
, double fDF
); // for LEGACY.CHIDIST, returns right tail
720 double GetChiSqDistCDF(double fX
, double fDF
); // for CHISQDIST, returns left tail
721 double GetChiSqDistPDF(double fX
, double fDF
); // probability density function
722 double GetFDist(double x
, double fF1
, double fF2
);
723 double GetTDist(double T
, double fDF
);
724 double Fakultaet(double x
);
725 double BinomKoeff(double n
, double k
);
726 double GetGamma(double x
);
727 double GetLogGamma(double x
);
728 double GetBeta(double fAlpha
, double fBeta
);
729 double GetLogBeta(double fAlpha
, double fBeta
);
734 void ScStdNormDist();
743 void ScPoissonDist();
746 void ScVariationen();
747 void ScVariationen2();
749 void ScHypGeomDist();
750 void ScLogNormDist();
754 void ScChiDist(); // for LEGACY.CHIDIST, returns right tail
755 void ScChiSqDist(); // returns left tail or density
756 void ScChiSqInv(); //invers to CHISQDIST
764 void ScNegBinomDist();
771 double GetMedian( ::std::vector
<double> & rArray
);
772 double GetPercentile( ::std::vector
<double> & rArray
, double fPercentile
);
773 void GetNumberSequenceArray( BYTE nParamCount
, ::std::vector
<double>& rArray
);
774 void GetSortArray(BYTE nParamCount
, ::std::vector
<double>& rSortArray
, ::std::vector
<long>* pIndexOrder
= NULL
);
775 void QuickSort(::std::vector
<double>& rSortArray
, ::std::vector
<long>* pIndexOrder
= NULL
);
785 void ScPercentrank();
794 void ScProbability();
804 //------------------------ Functions in interpr6.cxx -------------------------
806 static const double fMaxGammaArgument
; // defined in interpr3.cxx
808 double GetGammaContFraction(double fA
,double fX
);
809 double GetGammaSeries(double fA
,double fX
);
810 double GetLowRegIGamma(double fA
,double fX
); // lower regularized incomplete gamma function, GAMMAQ
811 double GetUpRegIGamma(double fA
,double fX
); // upper regularized incomplete gamma function, GAMMAP
812 // probability density function; fLambda is "scale" parameter
813 double GetGammaDistPDF(double fX
, double fAlpha
, double fLambda
);
814 // cumulative distribution function; fLambda is "scale" parameter
815 double GetGammaDist(double fX
, double fAlpha
, double fLambda
);
817 //----------------------------------------------------------------------------
819 ScInterpreter( ScFormulaCell
* pCell
, ScDocument
* pDoc
,
820 const ScAddress
&, ScTokenArray
& );
823 formula::StackVar
Interpret();
825 void SetError(USHORT nError
)
826 { if (nError
&& !nGlobalError
) nGlobalError
= nError
; }
828 USHORT
GetError() const { return nGlobalError
; }
829 formula::StackVar
GetResultType() const { return xResult
->GetType(); }
830 const String
& GetStringResult() const { return xResult
->GetString(); }
831 double GetNumResult() const { return xResult
->GetDouble(); }
832 formula::FormulaTokenRef
833 GetResultToken() const { return xResult
; }
834 short GetRetFormatType() const { return nRetFmtType
; }
835 ULONG
GetRetFormatIndex() const { return nRetFmtIndex
; }
839 inline void ScInterpreter::MatrixDoubleRefToMatrix()
841 if ( bMatrixFormula
&& GetStackType() == formula::svDoubleRef
)
843 GetTokenMatrixMap(); // make sure it exists, create if not.
844 PopDoubleRefPushMatrix();
849 inline bool ScInterpreter::MatrixParameterConversion()
851 if ( (bMatrixFormula
|| pCur
->HasForceArray()) && !pJumpMatrix
&& sp
> 0 )
852 return ConvertMatrixParameters();
857 inline ScTokenMatrixMap
& ScInterpreter::GetTokenMatrixMap()
859 if (!pTokenMatrixMap
)
860 pTokenMatrixMap
= CreateTokenMatrixMap();
861 return *pTokenMatrixMap
;
865 inline BOOL
ScInterpreter::MustHaveParamCount( short nAct
, short nMust
)
870 PushParameterExpected();
872 PushIllegalParameter();
877 inline BOOL
ScInterpreter::MustHaveParamCount( short nAct
, short nMust
, short nMax
)
879 if ( nMust
<= nAct
&& nAct
<= nMax
)
882 PushParameterExpected();
884 PushIllegalParameter();
889 inline BOOL
ScInterpreter::MustHaveParamCountMin( short nAct
, short nMin
)
893 PushParameterExpected();
898 inline BOOL
ScInterpreter::CheckStringResultLen( String
& rResult
, const String
& rAdd
)
900 if ( (ULONG
) rResult
.Len() + rAdd
.Len() > STRING_MAXLEN
)
902 SetError( errStringOverflow
);
910 inline void ScInterpreter::TreatDoubleError( double& rVal
)
912 if ( !::rtl::math::isFinite( rVal
) )
914 USHORT nErr
= GetDoubleErrorValue( rVal
);
918 SetError( errNoValue
);
925 inline double ScInterpreter::div( const double& fNumerator
, const double& fDenominator
)
927 return (fDenominator
!= 0.0) ? (fNumerator
/ fDenominator
) :
928 CreateDoubleError( errDivisionByZero
);