xref: /aoo42x/main/sc/source/core/inc/interpre.hxx (revision f53782eb)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_INTERPRE_HXX
25 #define SC_INTERPRE_HXX
26 
27 #include <math.h>
28 #include <rtl/math.hxx>
29 #include "formula/errorcodes.hxx"
30 #include "cell.hxx"
31 #include "scdll.hxx"
32 #include "document.hxx"
33 #include "scmatrix.hxx"
34 
35 #include <math.h>
36 #include <map>
37 
38 class ScDocument;
39 class SbxVariable;
40 class ScBaseCell;
41 class ScFormulaCell;
42 class SvNumberFormatter;
43 class ScDBRangeBase;
44 struct MatrixDoubleOp;
45 struct ScQueryParam;
46 struct ScDBQueryParamBase;
47 
48 struct ScCompare
49 {
50     double  nVal[2];
51     String* pVal[2];
52     sal_Bool    bVal[2];
53     sal_Bool    bEmpty[2];
54         ScCompare( String* p1, String* p2 )
55         {
56             pVal[ 0 ] = p1;
57             pVal[ 1 ] = p2;
58             bEmpty[0] = sal_False;
59             bEmpty[1] = sal_False;
60         }
61 };
62 
63 struct ScCompareOptions
64 {
65     ScQueryEntry        aQueryEntry;
66     bool                bRegEx;
67     bool                bMatchWholeCell;
68     bool                bIgnoreCase;
69 
70                         ScCompareOptions( ScDocument* pDoc, const ScQueryEntry& rEntry, bool bReg );
71 private:
72                         // Not implemented, prevent usage.
73                         ScCompareOptions();
74                         ScCompareOptions( const ScCompareOptions & );
75      ScCompareOptions&  operator=( const ScCompareOptions & );
76 };
77 
78 class ScToken;
79 
80 #define MAXSTACK      (4096 / sizeof(formula::FormulaToken*))
81 
82 class ScTokenStack
83 {
84 public:
85     DECL_FIXEDMEMPOOL_NEWDEL( ScTokenStack )
86     formula::FormulaToken* pPointer[ MAXSTACK ];
87 };
88 
89 enum ScIterFunc
90 {
91     ifSUM,     // Sum
92     ifSUMSQ,   // Sum squares
93     ifPRODUCT, // Product
94     ifAVERAGE, // Average
95     ifCOUNT,   // Count
96     ifCOUNT2,  // Count non-empty
97     ifMIN,     // Minimum
98     ifMAX      // Maximum
99 };
100 
101 enum ScIterFuncIf
102 {
103     ifSUMIF,    // Conditional sum
104     ifAVERAGEIF // Conditional average
105 };
106 
107 struct FormulaTokenRef_less
108 {
109     bool operator () ( const formula::FormulaConstTokenRef& r1, const formula::FormulaConstTokenRef& r2 ) const
110         { return &r1 < &r2; }
111 };
112 typedef ::std::map< const formula::FormulaConstTokenRef, formula::FormulaTokenRef, FormulaTokenRef_less> ScTokenMatrixMap;
113 
114 class ScInterpreter
115 {
116     // distibution function objects need the GetxxxDist methods
117     friend class ScGammaDistFunction;
118     friend class ScBetaDistFunction;
119     friend class ScTDistFunction;
120     friend class ScFDistFunction;
121     friend class ScChiDistFunction;
122     friend class ScChiSqDistFunction;
123 
124 public:
125     DECL_FIXEDMEMPOOL_NEWDEL( ScInterpreter )
126 
127     static void GlobalExit();           // aus ScGlobal::Clear() gerufen
128 
129     /// Could string be a regular expression?
130     /// If pDoc!=NULL the document options are taken into account and if
131     /// RegularExpressions are disabled the function returns sal_False regardless
132     /// of the string content.
133     static sal_Bool MayBeRegExp( const String& rStr, const ScDocument* pDoc );
134 
135     /// Fail safe division, returning an errDivisionByZero coded into a double
136     /// if denominator is 0.0
137     static inline double div( const double& fNumerator, const double& fDenominator );
138 
139     ScMatrixRef GetNewMat(SCSIZE nC, SCSIZE nR);
140 private:
141     static ScTokenStack*    pGlobalStack;
142     static sal_Bool             bGlobalStackInUse;
143 
144     formula::FormulaTokenIterator aCode;
145     ScAddress   aPos;
146     ScTokenArray& rArr;
147     ScDocument* pDok;
148     formula::FormulaTokenRef  xResult;
149     ScJumpMatrix*   pJumpMatrix;        // currently active array condition, if any
150     ScTokenMatrixMap* pTokenMatrixMap;  // map ScToken* to formula::FormulaTokenRef if in array condition
151     ScFormulaCell* pMyFormulaCell;      // the cell of this formula expression
152     SvNumberFormatter* pFormatter;
153 
154     const formula::FormulaToken*
155                 pCur;                // current token
156     String      aTempStr;               // for GetString()
157     ScTokenStack* pStackObj;            // contains the stacks
158     formula::FormulaToken**   pStack;                 // the current stack
159     sal_uInt16      nGlobalError;           // global (local to this formula expression) error
160     sal_uInt16      sp;                     // stack pointer
161     sal_uInt16      maxsp;                  // the maximal used stack pointer
162     sal_uLong       nFuncFmtIndex;          // NumberFormatIndex of a function
163     sal_uLong       nCurFmtIndex;           // current NumberFormatIndex
164     sal_uLong       nRetFmtIndex;           // NumberFormatIndex of an expression, if any
165     short       nFuncFmtType;           // NumberFormatType of a function
166     short       nCurFmtType;            // current NumberFormatType
167     short       nRetFmtType;            // NumberFormatType of an expression
168     sal_uInt16      mnStringNoValueError;   // the error set in ConvertStringToValue() if no value
169     sal_Bool        glSubTotal;             // flag for subtotal functions
170     sal_uInt8        cPar;                   // current count of parameters
171     sal_Bool        bCalcAsShown;           // precision as shown
172     sal_Bool        bMatrixFormula;         // formula cell is a matrix formula
173 
174 //---------------------------------Funktionen in interpre.cxx---------
175 // nMust <= nAct <= nMax ? ok : PushError
176 inline sal_Bool MustHaveParamCount( short nAct, short nMust );
177 inline sal_Bool MustHaveParamCount( short nAct, short nMust, short nMax );
178 inline sal_Bool MustHaveParamCountMin( short nAct, short nMin );
179 void PushParameterExpected();
180 void PushIllegalParameter();
181 void PushIllegalArgument();
182 void PushNoValue();
183 void PushNA();
184 //-------------------------------------------------------------------------
185 // Funktionen fuer den Zugriff auf das Document
186 //-------------------------------------------------------------------------
187 void ReplaceCell( ScAddress& );     // for TableOp
188 void ReplaceCell( SCCOL& rCol, SCROW& rRow, SCTAB& rTab );  // for TableOp
189 sal_Bool IsTableOpInRange( const ScRange& );
190 sal_uLong GetCellNumberFormat( const ScAddress&, const ScBaseCell* );
191 double ConvertStringToValue( const String& );
192 double GetCellValue( const ScAddress&, const ScBaseCell* );
193 double GetCellValueOrZero( const ScAddress&, const ScBaseCell* );
194 double GetValueCellValue( const ScAddress&, const ScValueCell* );
195 ScBaseCell* GetCell( const ScAddress& rPos )
196     { return pDok->GetCell( rPos ); }
197 void GetCellString( String& rStr, const ScBaseCell* pCell );
198 inline sal_uInt16 GetCellErrCode( const ScBaseCell* pCell )
199     { return pCell ? pCell->GetErrorCode() : 0; }
200 inline CellType GetCellType( const ScBaseCell* pCell )
201     { return pCell ? pCell->GetCellType() : CELLTYPE_NONE; }
202 /// Really empty or inherited emptiness.
203 inline sal_Bool HasCellEmptyData( const ScBaseCell* pCell )
204     { return pCell ? pCell->HasEmptyData() : sal_True; }
205 /// This includes inherited emptiness, which usually is regarded as value!
206 inline sal_Bool HasCellValueData( const ScBaseCell* pCell )
207     { return pCell ? pCell->HasValueData() : sal_False; }
208 /// Not empty and not value.
209 inline sal_Bool HasCellStringData( const ScBaseCell* pCell )
210     { return pCell ? pCell->HasStringData() : sal_False; }
211 
212 sal_Bool CreateDoubleArr(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
213                      SCCOL nCol2, SCROW nRow2, SCTAB nTab2, sal_uInt8* pCellArr);
214 sal_Bool CreateStringArr(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
215                      SCCOL nCol2, SCROW nRow2, SCTAB nTab2, sal_uInt8* pCellArr);
216 sal_Bool CreateCellArr(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
217                    SCCOL nCol2, SCROW nRow2, SCTAB nTab2, sal_uInt8* pCellArr);
218 
219 //-----------------------------------------------------------------------------
220 // Stack operations
221 //-----------------------------------------------------------------------------
222 
223 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
224     passed is not formula::FormulaErrorToken.
225     Increments RefCount of the original token if not substituted. */
226 void Push( formula::FormulaToken& r );
227 
228 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
229     Used to push RPN tokens or from within Push() or tokens that are already
230     explicit formula::FormulaErrorToken. Increments RefCount. */
231 void PushWithoutError( formula::FormulaToken& r );
232 
233 /** Clones the token to be pushed or substitutes with formula::FormulaErrorToken if
234     nGlobalError is set and the token passed is not formula::FormulaErrorToken. */
235 void PushTempToken( const formula::FormulaToken& );
236 
237 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
238     passed is not formula::FormulaErrorToken.
239     Increments RefCount of the original token if not substituted.
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     deleted in case of an errStackOverflow or if substituted with formula::FormulaErrorToken! */
243 void PushTempToken( formula::FormulaToken* );
244 
245 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
246     Used to push tokens from within PushTempToken() or tokens that are already
247     explicit formula::FormulaErrorToken. Increments RefCount.
248     ATTENTION! The token had to be allocated with `new' and must not be used
249     after this call if no RefCount was set because possibly it gets immediately
250     decremented again and thus deleted in case of an errStackOverflow! */
251 void PushTempTokenWithoutError( formula::FormulaToken* );
252 
253 /** If nGlobalError is set push formula::FormulaErrorToken.
254     If nGlobalError is not set do nothing.
255     Used in PushTempToken() and alike to simplify handling.
256     @return: <TRUE/> if nGlobalError. */
257 inline bool IfErrorPushError()
258 {
259     if (nGlobalError)
260     {
261         PushTempTokenWithoutError( new formula::FormulaErrorToken( nGlobalError));
262         return true;
263     }
264     return false;
265 }
266 
267 /** Obtain cell result / content from address and push as temp token.
268     bDisplayEmptyAsString is passed to ScEmptyCell in case of an empty cell
269     result. Also obtain number format and type if _both_, type and index
270     pointer, are not NULL. */
271 void PushCellResultToken( bool bDisplayEmptyAsString, const ScAddress & rAddress,
272         short * pRetTypeExpr, sal_uLong * pRetIndexExpr );
273 
274 formula::FormulaTokenRef PopToken();
275 void Pop();
276 void PopError();
277 double PopDouble();
278 const String& PopString();
279 void ValidateRef( const ScSingleRefData & rRef );
280 void ValidateRef( const ScComplexRefData & rRef );
281 void ValidateRef( const ScRefList & rRefList );
282 void SingleRefToVars( const ScSingleRefData & rRef, SCCOL & rCol, SCROW & rRow, SCTAB & rTab );
283 void PopSingleRef( ScAddress& );
284 void PopSingleRef(SCCOL& rCol, SCROW &rRow, SCTAB& rTab);
285 void DoubleRefToRange( const ScComplexRefData&, ScRange&, sal_Bool bDontCheckForTableOp = sal_False );
286 /** If formula::StackVar formula::svDoubleRef pop ScDoubleRefToken and return values of
287     ScComplexRefData.
288     Else if StackVar svRefList return values of the ScComplexRefData where
289     rRefInList is pointing to. rRefInList is incremented. If rRefInList was the
290     last element in list pop ScRefListToken and set rRefInList to 0, else
291     rParam is incremented (!) to allow usage as in
292     while(nParamCount--) PopDoubleRef(aRange,nParamCount,nRefInList);
293   */
294 void PopDoubleRef( ScRange & rRange, short & rParam, size_t & rRefInList );
295 void PopDoubleRef( ScRange&, sal_Bool bDontCheckForTableOp = sal_False );
296 void DoubleRefToVars( const ScToken* p,
297         SCCOL& rCol1, SCROW &rRow1, SCTAB& rTab1,
298         SCCOL& rCol2, SCROW &rRow2, SCTAB& rTab2,
299         sal_Bool bDontCheckForTableOp = sal_False );
300 ScDBRangeBase* PopDoubleRef();
301 void PopDoubleRef(SCCOL& rCol1, SCROW &rRow1, SCTAB& rTab1,
302                           SCCOL& rCol2, SCROW &rRow2, SCTAB& rTab2,
303                           sal_Bool bDontCheckForTableOp = sal_False );
304 sal_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 sal_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 //void PushByte(sal_uInt8 nVal);
315 void PushDouble(double nVal);
316 void PushInt( int nVal );
317 void PushStringBuffer( const sal_Unicode* pString );
318 void PushString( const String& rString );
319 void PushSingleRef(SCCOL nCol, SCROW nRow, SCTAB nTab);
320 void PushDoubleRef(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
321                                  SCCOL nCol2, SCROW nRow2, SCTAB nTab2);
322 void PushMatrix(ScMatrix* pMat);
323 void PushError( sal_uInt16 nError );
324 /// Raw stack type without default replacements.
325 formula::StackVar GetRawStackType();
326 /// Stack type with replacement of defaults, e.g. svMissing and formula::svEmptyCell will result in formula::svDouble.
327 formula::StackVar GetStackType();
328 // peek StackType of Parameter, Parameter 1 == TOS, 2 == TOS-1, ...
329 formula::StackVar GetStackType( sal_uInt8 nParam );
330 sal_uInt8 GetByte() { return cPar; }
331 // generiert aus DoubleRef positionsabhaengige SingleRef
332 sal_Bool DoubleRefToPosSingleRef( const ScRange& rRange, ScAddress& rAdr );
333 double GetDouble();
334 double GetDoubleWithDefault(double nDefault);
335 sal_Bool IsMissing();
336 sal_Bool GetBool() { return GetDouble() != 0.0; }
337 const String& GetString();
338 // pop matrix and obtain one element, upper left or according to jump matrix
339 ScMatValType GetDoubleOrStringFromMatrix( double& rDouble, String& rString );
340 ScMatrixRef CreateMatrixFromDoubleRef( const formula::FormulaToken* pToken,
341         SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
342         SCCOL nCol2, SCROW nRow2, SCTAB nTab2 );
343 inline ScTokenMatrixMap& GetTokenMatrixMap();
344 ScTokenMatrixMap* CreateTokenMatrixMap();
345 ScMatrixRef GetMatrix();
346 void ScTableOp();                                       // Mehrfachoperationen
347 void ScErrCell();                                       // Sonderbehandlung
348                                                         // Fehlerzelle
349 //-----------------------------allgemeine Hilfsfunktionen
350 void SetMaxIterationCount(sal_uInt16 n);
351 inline void CurFmtToFuncFmt()
352     { nFuncFmtType = nCurFmtType; nFuncFmtIndex = nCurFmtIndex; }
353 // Check for String overflow of rResult+rAdd and set error and erase rResult
354 // if so. Return sal_True if ok, sal_False if overflow
355 inline sal_Bool CheckStringResultLen( String& rResult, const String& rAdd );
356 // Set error according to rVal, and set rVal to 0.0 if there was an error.
357 inline void TreatDoubleError( double& rVal );
358 // Lookup using ScLookupCache, @returns sal_True if found and result address
359 bool LookupQueryWithCache( ScAddress & o_rResultPos,
360         const ScQueryParam & rParam ) const;
361 
362 //---------------------------------Funktionen in interpr1.cxx---------
363 void ScIfJump();
364 void ScChoseJump();
365 
366 // Be sure to only call this if pStack[sp-nStackLevel] really contains a
367 // ScJumpMatrixToken, no further checks are applied!
368 // Returns true if last jump was executed and result matrix pushed.
369 bool JumpMatrix( short nStackLevel );
370 
371 /** @param pOptions
372         NULL means case sensitivity document option is to be used!
373  */
374 double CompareFunc( const ScCompare& rComp, ScCompareOptions* pOptions = NULL );
375 double Compare();
376 /** @param pOptions
377         NULL means case sensitivity document option is to be used!
378  */
379 ScMatrixRef CompareMat( ScCompareOptions* pOptions = NULL );
380 ScMatrixRef QueryMat( ScMatrix* pMat, ScCompareOptions& rOptions );
381 void ScEqual();
382 void ScNotEqual();
383 void ScLess();
384 void ScGreater();
385 void ScLessEqual();
386 void ScGreaterEqual();
387 void ScAnd();
388 void ScOr();
389 void ScNot();
390 void ScNeg();
391 void ScPercentSign();
392 void ScIntersect();
393 void ScRangeFunc();
394 void ScUnionFunc();
395 void ScPi();
396 void ScRandom();
397 void ScTrue();
398 void ScFalse();
399 void ScDeg();
400 void ScRad();
401 void ScSin();
402 void ScCos();
403 void ScTan();
404 void ScCot();
405 void ScArcSin();
406 void ScArcCos();
407 void ScArcTan();
408 void ScArcCot();
409 void ScSinHyp();
410 void ScCosHyp();
411 void ScTanHyp();
412 void ScCotHyp();
413 void ScArcSinHyp();
414 void ScArcCosHyp();
415 void ScArcTanHyp();
416 void ScArcCotHyp();
417 void ScCosecant();
418 void ScSecant();
419 void ScCosecantHyp();
420 void ScSecantHyp();
421 void ScExp();
422 void ScLn();
423 void ScLog10();
424 void ScSqrt();
425 void ScIsEmpty();
426 short IsString();
427 void ScIsString();
428 void ScIsNonString();
429 void ScIsLogical();
430 void ScType();
431 void ScCell();
432 void ScIsRef();
433 void ScIsValue();
434 void ScIsFormula();
435 void ScFormula();
436 void ScRoman();
437 void ScArabic();
438 void ScIsNV();
439 void ScIsErr();
440 void ScIsError();
441 short IsEven();
442 void ScIsEven();
443 void ScIsOdd();
444 void ScN();
445 void ScCode();
446 void ScTrim();
447 void ScUpper();
448 void ScPropper();
449 void ScLower();
450 void ScLen();
451 void ScT();
452 void ScValue();
453 void ScClean();
454 void ScChar();
455 void ScJis();
456 void ScAsc();
457 void ScUnicode();
458 void ScUnichar();
459 void ScMin( sal_Bool bTextAsZero = sal_False );
460 void ScMax( sal_Bool bTextAsZero = sal_False );
461 double IterateParameters( ScIterFunc, sal_Bool bTextAsZero = sal_False );
462 void ScSumSQ();
463 void ScSum();
464 void ScProduct();
465 void ScAverage( sal_Bool bTextAsZero = sal_False );
466 void ScCount();
467 void ScCount2();
468 void GetStVarParams( double& rVal, double& rValCount, sal_Bool bTextAsZero = sal_False );
469 void ScVar( sal_Bool bTextAsZero = sal_False );
470 void ScVarP( sal_Bool bTextAsZero = sal_False );
471 void ScStDev( sal_Bool bTextAsZero = sal_False );
472 void ScStDevP( sal_Bool bTextAsZero = sal_False );
473 void ScColumns();
474 void ScRows();
475 void ScTables();
476 void ScColumn();
477 void ScRow();
478 void ScTable();
479 void ScMatch();
480 double IterateParametersIf( ScIterFuncIf );
481 void ScCountIf();
482 void ScSumIf();
483 void ScAverageIf();
484 void ScCountEmptyCells();
485 void ScLookup();
486 void ScHLookup();
487 void ScVLookup();
488 void ScSubTotal();
489 
490 // If upon call rMissingField==sal_True then the database field parameter may be
491 // missing (Xcl DCOUNT() syntax), or may be faked as missing by having the
492 // value 0.0 or being exactly the entire database range reference (old SO
493 // compatibility). If this was the case then rMissingField is set to sal_True upon
494 // return. If rMissingField==sal_False upon call all "missing cases" are considered
495 // to be an error.
496 ScDBQueryParamBase* GetDBParams( sal_Bool& rMissingField );
497 
498 void DBIterator( ScIterFunc );
499 void ScDBSum();
500 void ScDBCount();
501 void ScDBCount2();
502 void ScDBAverage();
503 void ScDBGet();
504 void ScDBMax();
505 void ScDBMin();
506 void ScDBProduct();
507 void GetDBStVarParams( double& rVal, double& rValCount );
508 void ScDBStdDev();
509 void ScDBStdDevP();
510 void ScDBVar();
511 void ScDBVarP();
512 void ScIndirect();
513 void ScAddressFunc();
514 void ScOffset();
515 void ScIndex();
516 void ScMultiArea();
517 void ScAreas();
518 void ScCurrency();
519 void ScReplace();
520 void ScFixed();
521 void ScFind();
522 void ScExact();
523 void ScLeft();
524 void ScRight();
525 void ScSearch();
526 void ScMid();
527 void ScText();
528 void ScSubstitute();
529 void ScRept();
530 void ScConcat();
531 void ScExternal();
532 void ScMissing();
533 void ScMacro();
534 sal_Bool SetSbxVariable( SbxVariable* pVar, const ScAddress& );
535 sal_Bool SetSbxVariable( SbxVariable* pVar, SCCOL nCol, SCROW nRow, SCTAB nTab );
536 void ScErrorType();
537 void ScDBArea();
538 void ScColRowNameAuto();
539 void ScExternalRef();
540 void ScGetPivotData();
541 void ScHyperLink();
542 void ScBahtText();
543 void ScTTT();
544 
545 //----------------Funktionen in interpr2.cxx---------------
546 
547 /** Obtain the date serial number for a given date.
548     @param bStrict
549         If sal_False, nYear < 100 takes the two-digit year setting into account,
550         and rollover of invalid calendar dates takes place, e.g. 1999-02-31 =>
551         1999-03-03.
552         If sal_True, the date passed must be a valid Gregorian calendar date. No
553         two-digit expanding or rollover is done.
554  */
555 double GetDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, bool bStrict );
556 
557 void ScGetActDate();
558 void ScGetActTime();
559 void ScGetYear();
560 void ScGetMonth();
561 void ScGetDay();
562 void ScGetDayOfWeek();
563 void ScGetWeekOfYear();
564 void ScEasterSunday();
565 void ScGetHour();
566 void ScGetMin();
567 void ScGetSec();
568 void ScPlusMinus();
569 void ScAbs();
570 void ScInt();
571 void ScEven();
572 void ScOdd();
573 void ScCeil();
574 void ScFloor();
575 void RoundNumber( rtl_math_RoundingMode eMode );
576 void ScRound();
577 void ScRoundUp();
578 void ScRoundDown();
579 void ScGetDateValue();
580 void ScGetTimeValue();
581 void ScArcTan2();
582 void ScLog();
583 void ScGetDate();
584 void ScGetTime();
585 void ScGetDiffDate();
586 void ScGetDiffDate360();
587 void ScPower();
588 void ScAmpersand();
589 void ScAdd();
590 void ScSub();
591 void ScMul();
592 void ScDiv();
593 void ScPow();
594 void ScCurrent();
595 void ScStyle();
596 void ScDde();
597 void ScBase();
598 void ScDecimal();
599 void ScConvert();
600 void ScEuroConvert();
601 
602 //----------------------- Finanzfunktionen ------------------------------------
603 void ScNPV();
604 void ScIRR();
605 void ScMIRR();
606 void ScISPMT();
607 
608 double ScGetBw(double fZins, double fZzr, double fRmz,
609                       double fZw, double fF);
610 void ScBW();
611 void ScDIA();
612 double ScGetGDA(double fWert, double fRest, double fDauer,
613                        double fPeriode, double fFaktor);
614 void ScGDA();
615 void ScGDA2();
616 double ScInterVDB(double fWert,double fRest,double fDauer,double fDauer1,
617                 double fPeriode,double fFaktor);
618 void ScVDB();
619 void ScLaufz();
620 void ScLIA();
621 double ScGetRmz(double fZins, double fZzr, double fBw,
622                        double fZw, double fF);
623 void ScRMZ();
624 void ScZGZ();
625 double ScGetZw(double fZins, double fZzr, double fRmz,
626                       double fBw, double fF);
627 void ScZW();
628 void ScZZR();
629 bool RateIteration(double fNper, double fPayment, double fPv,
630                                 double fFv, double fPayType, double& fGuess);
631 void ScZins();
632 double ScGetZinsZ(double fZins, double fZr, double fZzr, double fBw,
633                          double fZw, double fF, double& fRmz);
634 void ScZinsZ();
635 void ScKapz();
636 void ScKumZinsZ();
637 void ScKumKapZ();
638 void ScEffektiv();
639 void ScNominal();
640 void ScMod();
641 void ScBackSolver();
642 void ScIntercept();
643 //-------------------------Funktionen in interpr5.cxx--------------------------
644 double ScGetGCD(double fx, double fy);
645 void ScGCD();
646 void ScLCM();
647 //-------------------------- Matrixfunktionen ---------------------------------
648 
649 void ScMatValue();
650 void MEMat(ScMatrix* mM, SCSIZE n);
651 void ScMatDet();
652 void ScMatInv();
653 void ScMatMult();
654 void ScMatTrans();
655 void ScEMat();
656 void ScMatRef();
657 ScMatrixRef MatConcat(ScMatrix* pMat1, ScMatrix* pMat2);
658 void ScSumProduct();
659 void ScSumX2MY2();
660 void ScSumX2DY2();
661 void ScSumXMY2();
662 void ScGrowth();
663 bool CalculateSkew(double& fSum,double& fCount,double& vSum,std::vector<double>& values);
664 void CalculateSlopeIntercept(sal_Bool bSlope);
665 void CalculateSmallLarge(sal_Bool bSmall);
666 void CalculatePearsonCovar(sal_Bool _bPearson,sal_Bool _bStexy);
667 bool CalculateTest( sal_Bool _bTemplin
668                    ,const SCSIZE nC1, const SCSIZE nC2,const SCSIZE nR1,const SCSIZE nR2
669                    ,const ScMatrixRef& pMat1,const ScMatrixRef& pMat2
670                    ,double& fT,double& fF);
671 void CalculateLookup(sal_Bool HLookup);
672 bool FillEntry(ScQueryEntry& rEntry);
673 void CalculateAddSub(sal_Bool _bSub);
674 void CalculateTrendGrowth(bool _bGrowth);
675 void CalulateRGPRKP(bool _bRKP);
676 void CalculateSumX2MY2SumX2DY2(sal_Bool _bSumX2DY2);
677 void CalculateMatrixValue(const ScMatrix* pMat,SCSIZE nC,SCSIZE nR);
678 bool CheckMatrix(bool _bLOG,sal_uInt8& nCase,SCSIZE& nCX,SCSIZE& nCY,SCSIZE& nRX,SCSIZE& nRY,SCSIZE& M,SCSIZE& N,ScMatrixRef& pMatX,ScMatrixRef& pMatY);
679 void ScRGP();
680 void ScRKP();
681 void ScForecast();
682 //------------------------- Functions in interpr3.cxx -------------------------
683 void ScNoName();
684 void ScBadName();
685 // Statistik:
686 double phi(double x);
687 double integralPhi(double x);
688 double taylor(double* pPolynom, sal_uInt16 nMax, double x);
689 double gauss(double x);
690 double gaussinv(double x);
691 double GetBetaDist(double x, double alpha, double beta);  //cumulative distribution function
692 double GetBetaDistPDF(double fX, double fA, double fB); //probability density function)
693 double GetChiDist(double fChi, double fDF);     // for LEGACY.CHIDIST, returns right tail
694 double GetChiSqDistCDF(double fX, double fDF);  // for CHISQDIST, returns left tail
695 double GetChiSqDistPDF(double fX, double fDF);  // probability density function
696 double GetFDist(double x, double fF1, double fF2);
697 double GetTDist(double T, double fDF);
698 double Fakultaet(double x);
699 double BinomKoeff(double n, double k);
700 double GetGamma(double x);
701 double GetLogGamma(double x);
702 double GetBeta(double fAlpha, double fBeta);
703 double GetLogBeta(double fAlpha, double fBeta);
704 double GetBinomDistPMF(double x, double n, double p); //probability mass function
705 void ScLogGamma();
706 void ScGamma();
707 void ScPhi();
708 void ScGauss();
709 void ScStdNormDist();
710 void ScFisher();
711 void ScFisherInv();
712 void ScFact();
713 void ScNormDist();
714 void ScGammaDist();
715 void ScGammaInv();
716 void ScExpDist();
717 void ScBinomDist();
718 void ScPoissonDist();
719 void ScKombin();
720 void ScKombin2();
721 void ScVariationen();
722 void ScVariationen2();
723 void ScB();
724 void ScHypGeomDist();
725 void ScLogNormDist();
726 void ScLogNormInv();
727 void ScTDist();
728 void ScFDist();
729 void ScChiDist();   // for LEGACY.CHIDIST, returns right tail
730 void ScChiSqDist(); // returns left tail or density
731 void ScChiSqInv(); //invers to CHISQDIST
732 void ScWeibull();
733 void ScBetaDist();
734 void ScFInv();
735 void ScTInv();
736 void ScChiInv();
737 void ScBetaInv();
738 void ScCritBinom();
739 void ScNegBinomDist();
740 void ScKurt();
741 void ScHarMean();
742 void ScGeoMean();
743 void ScStandard();
744 void ScSkew();
745 void ScMedian();
746 double GetMedian( ::std::vector<double> & rArray );
747 double GetPercentile( ::std::vector<double> & rArray, double fPercentile );
748 void GetNumberSequenceArray( sal_uInt8 nParamCount, ::std::vector<double>& rArray );
749 void GetSortArray(sal_uInt8 nParamCount, ::std::vector<double>& rSortArray, ::std::vector<long>* pIndexOrder = NULL);
750 void QuickSort(::std::vector<double>& rSortArray, ::std::vector<long>* pIndexOrder = NULL);
751 void ScModalValue();
752 void ScAveDev();
753 void ScDevSq();
754 void ScZTest();
755 void ScTTest();
756 void ScFTest();
757 void ScChiTest();
758 void ScRank();
759 void ScPercentile();
760 void ScPercentrank();
761 void ScLarge();
762 void ScSmall();
763 void ScFrequency();
764 void ScQuartile();
765 void ScNormInv();
766 void ScSNormInv();
767 void ScConfidence();
768 void ScTrimMean();
769 void ScProbability();
770 void ScCorrel();
771 void ScCovar();
772 void ScPearson();
773 void ScRSQ();
774 void ScSTEXY();
775 void ScSlope();
776 void ScTrend();
777 void ScInfo();
778 
779 //------------------------ Functions in interpr6.cxx -------------------------
780 
781 static const double fMaxGammaArgument;  // defined in interpr3.cxx
782 
783 double GetGammaContFraction(double fA,double fX);
784 double GetGammaSeries(double fA,double fX);
785 double GetLowRegIGamma(double fA,double fX);    // lower regularized incomplete gamma function, GAMMAQ
786 double GetUpRegIGamma(double fA,double fX);     // upper regularized incomplete gamma function, GAMMAP
787 // probability density function; fLambda is "scale" parameter
788 double GetGammaDistPDF(double fX, double fAlpha, double fLambda);
789 // cumulative distribution function; fLambda is "scale" parameter
790 double GetGammaDist(double fX, double fAlpha, double fLambda);
791 
792 //----------------------------------------------------------------------------
793 public:
794     ScInterpreter( ScFormulaCell* pCell, ScDocument* pDoc,
795                     const ScAddress&, ScTokenArray& );
796     ~ScInterpreter();
797 
798     formula::StackVar Interpret();
799 
800     void SetError(sal_uInt16 nError)
801             { if (nError && !nGlobalError) nGlobalError = nError; }
802 
803     sal_uInt16 GetError()                               const   { return nGlobalError; }
804     formula::StackVar  GetResultType()              const   { return xResult->GetType(); }
805     const String&   GetStringResult()               const   { return xResult->GetString(); }
806     double          GetNumResult()                  const   { return xResult->GetDouble(); }
807     formula::FormulaTokenRef
808                     GetResultToken()                const   { return xResult; }
809     short           GetRetFormatType()              const   { return nRetFmtType; }
810     sal_uLong           GetRetFormatIndex()             const   { return nRetFmtIndex; }
811 };
812 
813 
814 inline void ScInterpreter::MatrixDoubleRefToMatrix()
815 {
816     if ( bMatrixFormula && GetStackType() == formula::svDoubleRef )
817     {
818         GetTokenMatrixMap();    // make sure it exists, create if not.
819         PopDoubleRefPushMatrix();
820     }
821 }
822 
823 
824 inline bool ScInterpreter::MatrixParameterConversion()
825 {
826     if ( (bMatrixFormula || pCur->HasForceArray()) && !pJumpMatrix && sp > 0 )
827         return ConvertMatrixParameters();
828     return false;
829 }
830 
831 
832 inline ScTokenMatrixMap& ScInterpreter::GetTokenMatrixMap()
833 {
834     if (!pTokenMatrixMap)
835         pTokenMatrixMap = CreateTokenMatrixMap();
836     return *pTokenMatrixMap;
837 }
838 
839 
840 inline sal_Bool ScInterpreter::MustHaveParamCount( short nAct, short nMust )
841 {
842     if ( nAct == nMust )
843         return sal_True;
844     if ( nAct < nMust )
845         PushParameterExpected();
846     else
847         PushIllegalParameter();
848     return sal_False;
849 }
850 
851 
852 inline sal_Bool ScInterpreter::MustHaveParamCount( short nAct, short nMust, short nMax )
853 {
854     if ( nMust <= nAct && nAct <= nMax )
855         return sal_True;
856     if ( nAct < nMust )
857         PushParameterExpected();
858     else
859         PushIllegalParameter();
860     return sal_False;
861 }
862 
863 
864 inline sal_Bool ScInterpreter::MustHaveParamCountMin( short nAct, short nMin )
865 {
866     if ( nAct >= nMin )
867         return sal_True;
868     PushParameterExpected();
869     return sal_False;
870 }
871 
872 
873 inline sal_Bool ScInterpreter::CheckStringResultLen( String& rResult, const String& rAdd )
874 {
875     if ( (sal_uLong) rResult.Len() + rAdd.Len() > STRING_MAXLEN )
876     {
877         SetError( errStringOverflow );
878         rResult.Erase();
879         return sal_False;
880     }
881     return sal_True;
882 }
883 
884 
885 inline void ScInterpreter::TreatDoubleError( double& rVal )
886 {
887     if ( !::rtl::math::isFinite( rVal ) )
888     {
889         sal_uInt16 nErr = GetDoubleErrorValue( rVal );
890         if ( nErr )
891             SetError( nErr );
892         else
893             SetError( errNoValue );
894         rVal = 0.0;
895     }
896 }
897 
898 
899 // static
900 inline double ScInterpreter::div( const double& fNumerator, const double& fDenominator )
901 {
902     return (fDenominator != 0.0) ? (fNumerator / fDenominator) :
903         CreateDoubleError( errDivisionByZero);
904 }
905 
906 #endif
907