xref: /aoo42x/main/sc/source/core/inc/interpre.hxx (revision 245212b4)
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 ScXor();
390 void ScNot();
391 void ScNeg();
392 void ScPercentSign();
393 void ScIntersect();
394 void ScRangeFunc();
395 void ScUnionFunc();
396 void ScPi();
397 void ScRandom();
398 void ScTrue();
399 void ScFalse();
400 void ScDeg();
401 void ScRad();
402 void ScSin();
403 void ScCos();
404 void ScTan();
405 void ScCot();
406 void ScArcSin();
407 void ScArcCos();
408 void ScArcTan();
409 void ScArcCot();
410 void ScSinHyp();
411 void ScCosHyp();
412 void ScTanHyp();
413 void ScCotHyp();
414 void ScArcSinHyp();
415 void ScArcCosHyp();
416 void ScArcTanHyp();
417 void ScArcCotHyp();
418 void ScCosecant();
419 void ScSecant();
420 void ScCosecantHyp();
421 void ScSecantHyp();
422 void ScExp();
423 void ScLn();
424 void ScLog10();
425 void ScSqrt();
426 void ScIsEmpty();
427 short IsString();
428 void ScIsString();
429 void ScIsNonString();
430 void ScIsLogical();
431 void ScType();
432 void ScCell();
433 void ScIsRef();
434 void ScIsValue();
435 void ScIsFormula();
436 void ScFormula();
437 void ScRoman();
438 void ScArabic();
439 void ScIsNV();
440 void ScIsErr();
441 void ScIsError();
442 short IsEven();
443 void ScIsEven();
444 void ScIsOdd();
445 void ScN();
446 void ScCode();
447 void ScTrim();
448 void ScUpper();
449 void ScPropper();
450 void ScLower();
451 void ScLen();
452 void ScT();
453 void ScValue();
454 void ScClean();
455 void ScChar();
456 void ScJis();
457 void ScAsc();
458 void ScUnicode();
459 void ScUnichar();
460 void ScMin( sal_Bool bTextAsZero = sal_False );
461 void ScMax( sal_Bool bTextAsZero = sal_False );
462 double IterateParameters( ScIterFunc, sal_Bool bTextAsZero = sal_False );
463 void ScSumSQ();
464 void ScSum();
465 void ScProduct();
466 void ScAverage( sal_Bool bTextAsZero = sal_False );
467 void ScCount();
468 void ScCount2();
469 void GetStVarParams( double& rVal, double& rValCount, sal_Bool bTextAsZero = sal_False );
470 void ScVar( sal_Bool bTextAsZero = sal_False );
471 void ScVarP( sal_Bool bTextAsZero = sal_False );
472 void ScStDev( sal_Bool bTextAsZero = sal_False );
473 void ScStDevP( sal_Bool bTextAsZero = sal_False );
474 void ScColumns();
475 void ScRows();
476 void ScTables();
477 void ScColumn();
478 void ScRow();
479 void ScTable();
480 void ScMatch();
481 double IterateParametersIf( ScIterFuncIf );
482 void ScCountIf();
483 void ScSumIf();
484 void ScAverageIf();
485 void ScCountEmptyCells();
486 void ScLookup();
487 void ScHLookup();
488 void ScVLookup();
489 void ScSubTotal();
490 
491 // If upon call rMissingField==sal_True then the database field parameter may be
492 // missing (Xcl DCOUNT() syntax), or may be faked as missing by having the
493 // value 0.0 or being exactly the entire database range reference (old SO
494 // compatibility). If this was the case then rMissingField is set to sal_True upon
495 // return. If rMissingField==sal_False upon call all "missing cases" are considered
496 // to be an error.
497 ScDBQueryParamBase* GetDBParams( sal_Bool& rMissingField );
498 
499 void DBIterator( ScIterFunc );
500 void ScDBSum();
501 void ScDBCount();
502 void ScDBCount2();
503 void ScDBAverage();
504 void ScDBGet();
505 void ScDBMax();
506 void ScDBMin();
507 void ScDBProduct();
508 void GetDBStVarParams( double& rVal, double& rValCount );
509 void ScDBStdDev();
510 void ScDBStdDevP();
511 void ScDBVar();
512 void ScDBVarP();
513 void ScIndirect();
514 void ScAddressFunc();
515 void ScOffset();
516 void ScIndex();
517 void ScMultiArea();
518 void ScAreas();
519 void ScCurrency();
520 void ScReplace();
521 void ScFixed();
522 void ScFind();
523 void ScExact();
524 void ScLeft();
525 void ScRight();
526 void ScSearch();
527 void ScMid();
528 void ScText();
529 void ScSubstitute();
530 void ScRept();
531 void ScConcat();
532 void ScExternal();
533 void ScMissing();
534 void ScMacro();
535 sal_Bool SetSbxVariable( SbxVariable* pVar, const ScAddress& );
536 sal_Bool SetSbxVariable( SbxVariable* pVar, SCCOL nCol, SCROW nRow, SCTAB nTab );
537 void ScErrorType();
538 void ScDBArea();
539 void ScColRowNameAuto();
540 void ScExternalRef();
541 void ScGetPivotData();
542 void ScHyperLink();
543 void ScBahtText();
544 void ScTTT();
545 
546 //----------------Funktionen in interpr2.cxx---------------
547 
548 /** Obtain the date serial number for a given date.
549     @param bStrict
550         If sal_False, nYear < 100 takes the two-digit year setting into account,
551         and rollover of invalid calendar dates takes place, e.g. 1999-02-31 =>
552         1999-03-03.
553         If sal_True, the date passed must be a valid Gregorian calendar date. No
554         two-digit expanding or rollover is done.
555  */
556 double GetDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, bool bStrict );
557 
558 void ScGetActDate();
559 void ScGetActTime();
560 void ScGetYear();
561 void ScGetMonth();
562 void ScGetDay();
563 void ScGetDayOfWeek();
564 void ScGetWeekOfYear();
565 void ScEasterSunday();
566 void ScGetHour();
567 void ScGetMin();
568 void ScGetSec();
569 void ScPlusMinus();
570 void ScAbs();
571 void ScInt();
572 void ScEven();
573 void ScOdd();
574 void ScCeil();
575 void ScFloor();
576 void RoundNumber( rtl_math_RoundingMode eMode );
577 void ScRound();
578 void ScRoundUp();
579 void ScRoundDown();
580 void ScGetDateValue();
581 void ScGetTimeValue();
582 void ScArcTan2();
583 void ScLog();
584 void ScGetDate();
585 void ScGetTime();
586 void ScGetDiffDate();
587 void ScGetDiffDate360();
588 void ScPower();
589 void ScAmpersand();
590 void ScAdd();
591 void ScSub();
592 void ScMul();
593 void ScDiv();
594 void ScPow();
595 void ScCurrent();
596 void ScStyle();
597 void ScDde();
598 void ScBase();
599 void ScDecimal();
600 void ScConvert();
601 void ScEuroConvert();
602 
603 //----------------------- Finanzfunktionen ------------------------------------
604 void ScNPV();
605 void ScIRR();
606 void ScMIRR();
607 void ScISPMT();
608 
609 double ScGetBw(double fZins, double fZzr, double fRmz,
610                       double fZw, double fF);
611 void ScBW();
612 void ScDIA();
613 double ScGetGDA(double fWert, double fRest, double fDauer,
614                        double fPeriode, double fFaktor);
615 void ScGDA();
616 void ScGDA2();
617 double ScInterVDB(double fWert,double fRest,double fDauer,double fDauer1,
618                 double fPeriode,double fFaktor);
619 void ScVDB();
620 void ScLaufz();
621 void ScLIA();
622 double ScGetRmz(double fZins, double fZzr, double fBw,
623                        double fZw, double fF);
624 void ScRMZ();
625 void ScZGZ();
626 double ScGetZw(double fZins, double fZzr, double fRmz,
627                       double fBw, double fF);
628 void ScZW();
629 void ScZZR();
630 bool RateIteration(double fNper, double fPayment, double fPv,
631                                 double fFv, double fPayType, double& fGuess);
632 void ScZins();
633 double ScGetZinsZ(double fZins, double fZr, double fZzr, double fBw,
634                          double fZw, double fF, double& fRmz);
635 void ScZinsZ();
636 void ScKapz();
637 void ScKumZinsZ();
638 void ScKumKapZ();
639 void ScEffektiv();
640 void ScNominal();
641 void ScMod();
642 void ScBackSolver();
643 void ScIntercept();
644 //-------------------------Funktionen in interpr5.cxx--------------------------
645 double ScGetGCD(double fx, double fy);
646 void ScGCD();
647 void ScLCM();
648 //-------------------------- Matrixfunktionen ---------------------------------
649 
650 void ScMatValue();
651 void MEMat(ScMatrix* mM, SCSIZE n);
652 void ScMatDet();
653 void ScMatInv();
654 void ScMatMult();
655 void ScMatTrans();
656 void ScEMat();
657 void ScMatRef();
658 ScMatrixRef MatConcat(ScMatrix* pMat1, ScMatrix* pMat2);
659 void ScSumProduct();
660 void ScSumX2MY2();
661 void ScSumX2DY2();
662 void ScSumXMY2();
663 void ScGrowth();
664 bool CalculateSkew(double& fSum,double& fCount,double& vSum,std::vector<double>& values);
665 void CalculateSlopeIntercept(sal_Bool bSlope);
666 void CalculateSmallLarge(sal_Bool bSmall);
667 void CalculatePearsonCovar(sal_Bool _bPearson,sal_Bool _bStexy);
668 bool CalculateTest( sal_Bool _bTemplin
669                    ,const SCSIZE nC1, const SCSIZE nC2,const SCSIZE nR1,const SCSIZE nR2
670                    ,const ScMatrixRef& pMat1,const ScMatrixRef& pMat2
671                    ,double& fT,double& fF);
672 void CalculateLookup(sal_Bool HLookup);
673 bool FillEntry(ScQueryEntry& rEntry);
674 void CalculateAddSub(sal_Bool _bSub);
675 void CalculateTrendGrowth(bool _bGrowth);
676 void CalulateRGPRKP(bool _bRKP);
677 void CalculateSumX2MY2SumX2DY2(sal_Bool _bSumX2DY2);
678 void CalculateMatrixValue(const ScMatrix* pMat,SCSIZE nC,SCSIZE nR);
679 bool CheckMatrix(bool _bLOG,sal_uInt8& nCase,SCSIZE& nCX,SCSIZE& nCY,SCSIZE& nRX,SCSIZE& nRY,SCSIZE& M,SCSIZE& N,ScMatrixRef& pMatX,ScMatrixRef& pMatY);
680 void ScRGP();
681 void ScRKP();
682 void ScForecast();
683 //------------------------- Functions in interpr3.cxx -------------------------
684 void ScNoName();
685 void ScBadName();
686 // Statistik:
687 double phi(double x);
688 double integralPhi(double x);
689 double taylor(double* pPolynom, sal_uInt16 nMax, double x);
690 double gauss(double x);
691 double gaussinv(double x);
692 double GetBetaDist(double x, double alpha, double beta);  //cumulative distribution function
693 double GetBetaDistPDF(double fX, double fA, double fB); //probability density function)
694 double GetChiDist(double fChi, double fDF);     // for LEGACY.CHIDIST, returns right tail
695 double GetChiSqDistCDF(double fX, double fDF);  // for CHISQDIST, returns left tail
696 double GetChiSqDistPDF(double fX, double fDF);  // probability density function
697 double GetFDist(double x, double fF1, double fF2);
698 double GetTDist(double T, double fDF);
699 double Fakultaet(double x);
700 double BinomKoeff(double n, double k);
701 double GetGamma(double x);
702 double GetLogGamma(double x);
703 double GetBeta(double fAlpha, double fBeta);
704 double GetLogBeta(double fAlpha, double fBeta);
705 double GetBinomDistPMF(double x, double n, double p); //probability mass function
706 void ScLogGamma();
707 void ScGamma();
708 void ScPhi();
709 void ScGauss();
710 void ScStdNormDist();
711 void ScFisher();
712 void ScFisherInv();
713 void ScFact();
714 void ScNormDist();
715 void ScGammaDist();
716 void ScGammaInv();
717 void ScExpDist();
718 void ScBinomDist();
719 void ScPoissonDist();
720 void ScKombin();
721 void ScKombin2();
722 void ScVariationen();
723 void ScVariationen2();
724 void ScB();
725 void ScHypGeomDist();
726 void ScLogNormDist();
727 void ScLogNormInv();
728 void ScTDist();
729 void ScFDist();
730 void ScChiDist();   // for LEGACY.CHIDIST, returns right tail
731 void ScChiSqDist(); // returns left tail or density
732 void ScChiSqInv(); //invers to CHISQDIST
733 void ScWeibull();
734 void ScBetaDist();
735 void ScFInv();
736 void ScTInv();
737 void ScChiInv();
738 void ScBetaInv();
739 void ScCritBinom();
740 void ScNegBinomDist();
741 void ScKurt();
742 void ScHarMean();
743 void ScGeoMean();
744 void ScStandard();
745 void ScSkew();
746 void ScMedian();
747 double GetMedian( ::std::vector<double> & rArray );
748 double GetPercentile( ::std::vector<double> & rArray, double fPercentile );
749 void GetNumberSequenceArray( sal_uInt8 nParamCount, ::std::vector<double>& rArray );
750 void GetSortArray(sal_uInt8 nParamCount, ::std::vector<double>& rSortArray, ::std::vector<long>* pIndexOrder = NULL);
751 void QuickSort(::std::vector<double>& rSortArray, ::std::vector<long>* pIndexOrder = NULL);
752 void ScModalValue();
753 void ScAveDev();
754 void ScDevSq();
755 void ScZTest();
756 void ScTTest();
757 void ScFTest();
758 void ScChiTest();
759 void ScRank();
760 void ScPercentile();
761 void ScPercentrank();
762 void ScLarge();
763 void ScSmall();
764 void ScFrequency();
765 void ScQuartile();
766 void ScNormInv();
767 void ScSNormInv();
768 void ScConfidence();
769 void ScTrimMean();
770 void ScProbability();
771 void ScCorrel();
772 void ScCovar();
773 void ScPearson();
774 void ScRSQ();
775 void ScSTEXY();
776 void ScSlope();
777 void ScTrend();
778 void ScInfo();
779 
780 //------------------------ Functions in interpr6.cxx -------------------------
781 
782 static const double fMaxGammaArgument;  // defined in interpr3.cxx
783 
784 double GetGammaContFraction(double fA,double fX);
785 double GetGammaSeries(double fA,double fX);
786 double GetLowRegIGamma(double fA,double fX);    // lower regularized incomplete gamma function, GAMMAQ
787 double GetUpRegIGamma(double fA,double fX);     // upper regularized incomplete gamma function, GAMMAP
788 // probability density function; fLambda is "scale" parameter
789 double GetGammaDistPDF(double fX, double fAlpha, double fLambda);
790 // cumulative distribution function; fLambda is "scale" parameter
791 double GetGammaDist(double fX, double fAlpha, double fLambda);
792 
793 //----------------------------------------------------------------------------
794 public:
795     ScInterpreter( ScFormulaCell* pCell, ScDocument* pDoc,
796                     const ScAddress&, ScTokenArray& );
797     ~ScInterpreter();
798 
799     formula::StackVar Interpret();
800 
801     void SetError(sal_uInt16 nError)
802             { if (nError && !nGlobalError) nGlobalError = nError; }
803 
804     sal_uInt16 GetError()                               const   { return nGlobalError; }
805     formula::StackVar  GetResultType()              const   { return xResult->GetType(); }
806     const String&   GetStringResult()               const   { return xResult->GetString(); }
807     double          GetNumResult()                  const   { return xResult->GetDouble(); }
808     formula::FormulaTokenRef
809                     GetResultToken()                const   { return xResult; }
810     short           GetRetFormatType()              const   { return nRetFmtType; }
811     sal_uLong           GetRetFormatIndex()             const   { return nRetFmtIndex; }
812 };
813 
814 
815 inline void ScInterpreter::MatrixDoubleRefToMatrix()
816 {
817     if ( bMatrixFormula && GetStackType() == formula::svDoubleRef )
818     {
819         GetTokenMatrixMap();    // make sure it exists, create if not.
820         PopDoubleRefPushMatrix();
821     }
822 }
823 
824 
825 inline bool ScInterpreter::MatrixParameterConversion()
826 {
827     if ( (bMatrixFormula || pCur->HasForceArray()) && !pJumpMatrix && sp > 0 )
828         return ConvertMatrixParameters();
829     return false;
830 }
831 
832 
833 inline ScTokenMatrixMap& ScInterpreter::GetTokenMatrixMap()
834 {
835     if (!pTokenMatrixMap)
836         pTokenMatrixMap = CreateTokenMatrixMap();
837     return *pTokenMatrixMap;
838 }
839 
840 
841 inline sal_Bool ScInterpreter::MustHaveParamCount( short nAct, short nMust )
842 {
843     if ( nAct == nMust )
844         return sal_True;
845     if ( nAct < nMust )
846         PushParameterExpected();
847     else
848         PushIllegalParameter();
849     return sal_False;
850 }
851 
852 
853 inline sal_Bool ScInterpreter::MustHaveParamCount( short nAct, short nMust, short nMax )
854 {
855     if ( nMust <= nAct && nAct <= nMax )
856         return sal_True;
857     if ( nAct < nMust )
858         PushParameterExpected();
859     else
860         PushIllegalParameter();
861     return sal_False;
862 }
863 
864 
865 inline sal_Bool ScInterpreter::MustHaveParamCountMin( short nAct, short nMin )
866 {
867     if ( nAct >= nMin )
868         return sal_True;
869     PushParameterExpected();
870     return sal_False;
871 }
872 
873 
874 inline sal_Bool ScInterpreter::CheckStringResultLen( String& rResult, const String& rAdd )
875 {
876     if ( (sal_uLong) rResult.Len() + rAdd.Len() > STRING_MAXLEN )
877     {
878         SetError( errStringOverflow );
879         rResult.Erase();
880         return sal_False;
881     }
882     return sal_True;
883 }
884 
885 
886 inline void ScInterpreter::TreatDoubleError( double& rVal )
887 {
888     if ( !::rtl::math::isFinite( rVal ) )
889     {
890         sal_uInt16 nErr = GetDoubleErrorValue( rVal );
891         if ( nErr )
892             SetError( nErr );
893         else
894             SetError( errNoValue );
895         rVal = 0.0;
896     }
897 }
898 
899 
900 // static
901 inline double ScInterpreter::div( const double& fNumerator, const double& fDenominator )
902 {
903     return (fDenominator != 0.0) ? (fNumerator / fDenominator) :
904         CreateDoubleError( errDivisionByZero);
905 }
906 
907 #endif
908