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