merge the formfield patch from ooo-build
[ooovba.git] / sc / source / core / inc / interpre.hxx
blobb1ef2ef4510b63ccf86d92d8d82b7a315886343f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
36 #include <math.h>
37 #include <rtl/math.hxx>
38 #include "formula/errorcodes.hxx"
39 #include "cell.hxx"
40 #include "scdll.hxx"
41 #include "document.hxx"
42 #include "scmatrix.hxx"
44 #if SC_SPEW_ENABLED
45 #include "scspew.hxx"
46 #endif
48 #include <math.h>
49 #include <map>
51 class ScDocument;
52 class SbxVariable;
53 class ScBaseCell;
54 class ScFormulaCell;
55 class SvNumberFormatter;
56 class ScDBRangeBase;
57 struct MatrixDoubleOp;
58 struct ScQueryParam;
59 struct ScDBQueryParamBase;
61 struct ScCompare
63 double nVal[2];
64 String* pVal[2];
65 BOOL bVal[2];
66 BOOL bEmpty[2];
67 ScCompare( String* p1, String* p2 )
69 pVal[ 0 ] = p1;
70 pVal[ 1 ] = p2;
71 bEmpty[0] = FALSE;
72 bEmpty[1] = FALSE;
76 struct ScCompareOptions
78 ScQueryEntry aQueryEntry;
79 bool bRegEx;
80 bool bMatchWholeCell;
81 bool bIgnoreCase;
83 ScCompareOptions( ScDocument* pDoc, const ScQueryEntry& rEntry, bool bReg );
84 private:
85 // Not implemented, prevent usage.
86 ScCompareOptions();
87 ScCompareOptions( const ScCompareOptions & );
88 ScCompareOptions& operator=( const ScCompareOptions & );
91 class ScToken;
93 #define MAXSTACK (4096 / sizeof(formula::FormulaToken*))
95 class ScTokenStack
97 public:
98 DECL_FIXEDMEMPOOL_NEWDEL( ScTokenStack )
99 formula::FormulaToken* pPointer[ MAXSTACK ];
102 enum ScIterFunc {
103 ifSUM, // Aufsummieren
104 ifSUMSQ, // Quadratsummen
105 ifPRODUCT, // Multiplizieren
106 ifAVERAGE, // Durchschnitt
107 ifCOUNT, // Anzahl Werte
108 ifCOUNT2, // Anzahl Werte (nichtleer)
109 ifMIN, // Minimum
110 ifMAX // Maximum
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;
120 class ScInterpreter
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;
130 public:
131 DECL_FIXEDMEMPOOL_NEWDEL( ScInterpreter )
132 #if SC_SPEW_ENABLED
133 static ScSpew theSpew;
134 #endif
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);
150 enum VolatileType {
151 VOLATILE,
152 VOLATILE_MACRO,
153 NOT_VOLATILE
156 VolatileType GetVolatileType() const;
158 private:
159 static ScTokenStack* pGlobalStack;
160 static BOOL bGlobalStackInUse;
162 formula::FormulaTokenIterator aCode;
163 ScAddress aPos;
164 ScTokenArray& rArr;
165 ScDocument* pDok;
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();
201 void PushNoValue();
202 void PushNA();
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 //-----------------------------------------------------------------------------
239 // Stack operations
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()
278 if (nGlobalError)
280 PushTempTokenWithoutError( new formula::FormulaErrorToken( nGlobalError));
281 return true;
283 return false;
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();
294 void Pop();
295 void PopError();
296 double PopDouble();
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
306 ScComplexRefData.
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 );
352 double GetDouble();
353 double GetDoubleWithDefault(double nDefault);
354 BOOL IsMissing();
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
367 // Fehlerzelle
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---------
382 void ScIfJump();
383 void ScChoseJump();
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 );
390 /** @param pOptions
391 NULL means case sensitivity document option is to be used!
393 double CompareFunc( const ScCompare& rComp, ScCompareOptions* pOptions = NULL );
394 double Compare();
395 /** @param pOptions
396 NULL means case sensitivity document option is to be used!
398 ScMatrixRef CompareMat( ScCompareOptions* pOptions = NULL );
399 ScMatrixRef QueryMat( ScMatrix* pMat, ScCompareOptions& rOptions );
400 void ScEqual();
401 void ScNotEqual();
402 void ScLess();
403 void ScGreater();
404 void ScLessEqual();
405 void ScGreaterEqual();
406 void ScAnd();
407 void ScOr();
408 void ScNot();
409 void ScNeg();
410 void ScPercentSign();
411 void ScIntersect();
412 void ScRangeFunc();
413 void ScUnionFunc();
414 void ScPi();
415 void ScRandom();
416 void ScTrue();
417 void ScFalse();
418 void ScDeg();
419 void ScRad();
420 void ScSin();
421 void ScCos();
422 void ScTan();
423 void ScCot();
424 void ScArcSin();
425 void ScArcCos();
426 void ScArcTan();
427 void ScArcCot();
428 void ScSinHyp();
429 void ScCosHyp();
430 void ScTanHyp();
431 void ScCotHyp();
432 void ScArcSinHyp();
433 void ScArcCosHyp();
434 void ScArcTanHyp();
435 void ScArcCotHyp();
436 void ScExp();
437 void ScLn();
438 void ScLog10();
439 void ScSqrt();
440 void ScIsEmpty();
441 short IsString();
442 void ScIsString();
443 void ScIsNonString();
444 void ScIsLogical();
445 void ScType();
446 void ScCell();
447 void ScIsRef();
448 void ScIsValue();
449 void ScIsFormula();
450 void ScFormula();
451 void ScRoman();
452 void ScArabic();
453 void ScIsNV();
454 void ScIsErr();
455 void ScIsError();
456 short IsEven();
457 void ScIsEven();
458 void ScIsOdd();
459 void ScN();
460 void ScCode();
461 void ScTrim();
462 void ScUpper();
463 void ScPropper();
464 void ScLower();
465 void ScLen();
466 void ScT();
467 void ScValue();
468 void ScClean();
469 void ScChar();
470 void ScJis();
471 void ScAsc();
472 void ScUnicode();
473 void ScUnichar();
474 void ScMin( BOOL bTextAsZero = FALSE );
475 void ScMax( BOOL bTextAsZero = FALSE );
476 double IterateParameters( ScIterFunc, BOOL bTextAsZero = FALSE );
477 void ScSumSQ();
478 void ScSum();
479 void ScProduct();
480 void ScAverage( BOOL bTextAsZero = FALSE );
481 void ScCount();
482 void ScCount2();
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 );
488 void ScColumns();
489 void ScRows();
490 void ScTables();
491 void ScColumn();
492 void ScRow();
493 void ScTable();
494 void ScMatch();
495 void ScCountIf();
496 void ScSumIf();
497 void ScCountEmptyCells();
498 void ScLookup();
499 void ScHLookup();
500 void ScVLookup();
501 void ScSubTotal();
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
508 // to be an error.
509 ScDBQueryParamBase* GetDBParams( BOOL& rMissingField );
511 void DBIterator( ScIterFunc );
512 void ScDBSum();
513 void ScDBCount();
514 void ScDBCount2();
515 void ScDBAverage();
516 void ScDBGet();
517 void ScDBMax();
518 void ScDBMin();
519 void ScDBProduct();
520 void GetDBStVarParams( double& rVal, double& rValCount );
521 void ScDBStdDev();
522 void ScDBStdDevP();
523 void ScDBVar();
524 void ScDBVarP();
525 void ScIndirect();
526 void ScAddressFunc();
527 void ScOffset();
528 void ScIndex();
529 void ScMultiArea();
530 void ScAreas();
531 void ScCurrency();
532 void ScReplace();
533 void ScFixed();
534 void ScFind();
535 void ScExact();
536 void ScLeft();
537 void ScRight();
538 void ScSearch();
539 void ScMid();
540 void ScText();
541 void ScSubstitute();
542 void ScRept();
543 void ScConcat();
544 void ScExternal();
545 void ScMissing();
546 void ScMacro();
547 BOOL SetSbxVariable( SbxVariable* pVar, const ScAddress& );
548 BOOL SetSbxVariable( SbxVariable* pVar, SCCOL nCol, SCROW nRow, SCTAB nTab );
549 void ScErrorType();
550 void ScDBArea();
551 void ScColRowNameAuto();
552 void ScExternalRef();
553 void ScGetPivotData();
554 void ScHyperLink();
555 void ScBahtText();
556 void ScCalcTeam();
557 void ScAnswer();
558 void ScTTT();
559 void ScSpewFunc();
560 void ScGame();
562 //----------------Funktionen in interpr2.cxx---------------
564 /** Obtain the date serial number for a given date.
565 @param bStrict
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 =>
568 1999-03-03.
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 );
574 void ScGetActDate();
575 void ScGetActTime();
576 void ScGetYear();
577 void ScGetMonth();
578 void ScGetDay();
579 void ScGetDayOfWeek();
580 void ScGetWeekOfYear();
581 void ScEasterSunday();
582 void ScGetHour();
583 void ScGetMin();
584 void ScGetSec();
585 void ScPlusMinus();
586 void ScAbs();
587 void ScInt();
588 void ScEven();
589 void ScOdd();
590 void ScCeil();
591 void ScFloor();
592 void RoundNumber( rtl_math_RoundingMode eMode );
593 void ScRound();
594 void ScRoundUp();
595 void ScRoundDown();
596 void ScGetDateValue();
597 void ScGetTimeValue();
598 void ScArcTan2();
599 void ScLog();
600 void ScGetDate();
601 void ScGetTime();
602 void ScGetDiffDate();
603 void ScGetDiffDate360();
604 void ScPower();
605 void ScAmpersand();
606 void ScAdd();
607 void ScSub();
608 void ScMul();
609 void ScDiv();
610 void ScPow();
611 void ScCurrent();
612 void ScStyle();
613 void ScDde();
614 void ScBase();
615 void ScDecimal();
616 void ScConvert();
617 void ScEuroConvert();
619 //----------------------- Finanzfunktionen ------------------------------------
620 void ScNPV();
621 void ScIRR();
622 void ScMIRR();
623 void ScISPMT();
625 double ScGetBw(double fZins, double fZzr, double fRmz,
626 double fZw, double fF);
627 void ScBW();
628 void ScDIA();
629 double ScGetGDA(double fWert, double fRest, double fDauer,
630 double fPeriode, double fFaktor);
631 void ScGDA();
632 void ScGDA2();
633 double ScInterVDB(double fWert,double fRest,double fDauer,double fDauer1,
634 double fPeriode,double fFaktor);
635 void ScVDB();
636 void ScLaufz();
637 void ScLIA();
638 double ScGetRmz(double fZins, double fZzr, double fBw,
639 double fZw, double fF);
640 void ScRMZ();
641 void ScZGZ();
642 double ScGetZw(double fZins, double fZzr, double fRmz,
643 double fBw, double fF);
644 void ScZW();
645 void ScZZR();
646 bool RateIteration(double fNper, double fPayment, double fPv,
647 double fFv, double fPayType, double& fGuess);
648 void ScZins();
649 double ScGetZinsZ(double fZins, double fZr, double fZzr, double fBw,
650 double fZw, double fF, double& fRmz);
651 void ScZinsZ();
652 void ScKapz();
653 void ScKumZinsZ();
654 void ScKumKapZ();
655 void ScEffektiv();
656 void ScNominal();
657 void ScMod();
658 void ScBackSolver();
659 void ScIntercept();
660 //-------------------------Funktionen in interpr5.cxx--------------------------
661 double ScGetGCD(double fx, double fy);
662 void ScGCD();
663 void ScLCM();
664 //-------------------------- Matrixfunktionen ---------------------------------
666 void ScMatValue();
667 void MEMat(ScMatrix* mM, SCSIZE n);
668 void MFastMult(ScMatrix* pA, ScMatrix* pB, ScMatrix* pR, SCSIZE n, SCSIZE m, SCSIZE l);
669 void ScMatDet();
670 void ScMatInv();
671 void ScMatMult();
672 void ScMatTrans();
673 void ScEMat();
674 void ScMatRef();
675 ScMatrixRef MatConcat(ScMatrix* pMat1, ScMatrix* pMat2);
676 void ScSumProduct();
677 void ScSumX2MY2();
678 void ScSumX2DY2();
679 void ScSumXMY2();
680 void ScGrowth();
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);
705 void ScRGP();
706 void ScRKP();
707 void ScForecast();
708 //------------------------- Functions in interpr3.cxx -------------------------
709 void ScNoName();
710 void ScBadName();
711 // Statistik:
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);
730 void ScLogGamma();
731 void ScGamma();
732 void ScPhi();
733 void ScGauss();
734 void ScStdNormDist();
735 void ScFisher();
736 void ScFisherInv();
737 void ScFact();
738 void ScNormDist();
739 void ScGammaDist();
740 void ScGammaInv();
741 void ScExpDist();
742 void ScBinomDist();
743 void ScPoissonDist();
744 void ScKombin();
745 void ScKombin2();
746 void ScVariationen();
747 void ScVariationen2();
748 void ScB();
749 void ScHypGeomDist();
750 void ScLogNormDist();
751 void ScLogNormInv();
752 void ScTDist();
753 void ScFDist();
754 void ScChiDist(); // for LEGACY.CHIDIST, returns right tail
755 void ScChiSqDist(); // returns left tail or density
756 void ScChiSqInv(); //invers to CHISQDIST
757 void ScWeibull();
758 void ScBetaDist();
759 void ScFInv();
760 void ScTInv();
761 void ScChiInv();
762 void ScBetaInv();
763 void ScCritBinom();
764 void ScNegBinomDist();
765 void ScKurt();
766 void ScHarMean();
767 void ScGeoMean();
768 void ScStandard();
769 void ScSkew();
770 void ScMedian();
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);
776 void ScModalValue();
777 void ScAveDev();
778 void ScDevSq();
779 void ScZTest();
780 void ScTTest();
781 void ScFTest();
782 void ScChiTest();
783 void ScRank();
784 void ScPercentile();
785 void ScPercentrank();
786 void ScLarge();
787 void ScSmall();
788 void ScFrequency();
789 void ScQuartile();
790 void ScNormInv();
791 void ScSNormInv();
792 void ScConfidence();
793 void ScTrimMean();
794 void ScProbability();
795 void ScCorrel();
796 void ScCovar();
797 void ScPearson();
798 void ScRSQ();
799 void ScSTEXY();
800 void ScSlope();
801 void ScTrend();
802 void ScInfo();
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 //----------------------------------------------------------------------------
818 public:
819 ScInterpreter( ScFormulaCell* pCell, ScDocument* pDoc,
820 const ScAddress&, ScTokenArray& );
821 ~ScInterpreter();
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();
853 return false;
857 inline ScTokenMatrixMap& ScInterpreter::GetTokenMatrixMap()
859 if (!pTokenMatrixMap)
860 pTokenMatrixMap = CreateTokenMatrixMap();
861 return *pTokenMatrixMap;
865 inline BOOL ScInterpreter::MustHaveParamCount( short nAct, short nMust )
867 if ( nAct == nMust )
868 return TRUE;
869 if ( nAct < nMust )
870 PushParameterExpected();
871 else
872 PushIllegalParameter();
873 return FALSE;
877 inline BOOL ScInterpreter::MustHaveParamCount( short nAct, short nMust, short nMax )
879 if ( nMust <= nAct && nAct <= nMax )
880 return TRUE;
881 if ( nAct < nMust )
882 PushParameterExpected();
883 else
884 PushIllegalParameter();
885 return FALSE;
889 inline BOOL ScInterpreter::MustHaveParamCountMin( short nAct, short nMin )
891 if ( nAct >= nMin )
892 return TRUE;
893 PushParameterExpected();
894 return FALSE;
898 inline BOOL ScInterpreter::CheckStringResultLen( String& rResult, const String& rAdd )
900 if ( (ULONG) rResult.Len() + rAdd.Len() > STRING_MAXLEN )
902 SetError( errStringOverflow );
903 rResult.Erase();
904 return FALSE;
906 return TRUE;
910 inline void ScInterpreter::TreatDoubleError( double& rVal )
912 if ( !::rtl::math::isFinite( rVal ) )
914 USHORT nErr = GetDoubleErrorValue( rVal );
915 if ( nErr )
916 SetError( nErr );
917 else
918 SetError( errNoValue );
919 rVal = 0.0;
924 // static
925 inline double ScInterpreter::div( const double& fNumerator, const double& fDenominator )
927 return (fDenominator != 0.0) ? (fNumerator / fDenominator) :
928 CreateDoubleError( errDivisionByZero);
931 #endif