re-enabled user-defined numeric fields for dBase export
[LibreOffice.git] / sc / source / core / inc / interpre.hxx
blob582df8b945db138a3d16a4f57de596240136dd06
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef SC_INTERPRE_HXX
21 #define SC_INTERPRE_HXX
23 #include <math.h>
24 #include <rtl/math.hxx>
25 #include <rtl/ustring.hxx>
26 #include "formula/errorcodes.hxx"
27 #include "formula/tokenarray.hxx"
28 #include "scdll.hxx"
29 #include "scmatrix.hxx"
30 #include "externalrefmgr.hxx"
31 #include "calcconfig.hxx"
32 #include "token.hxx"
34 #include <map>
36 class ScDocument;
37 class SbxVariable;
38 class ScValueCell;
39 class ScFormulaCell;
40 class SvNumberFormatter;
41 class ScDBRangeBase;
42 struct ScQueryParam;
43 struct ScDBQueryParamBase;
44 struct ScQueryEntry;
46 struct ScCompare;
47 struct ScCompareOptions;
48 struct ScSingleRefData;
49 struct ScComplexRefData;
51 class ScToken;
52 class ScJumpMatrix;
53 class ScCellIterator;
54 struct ScRefCellValue;
56 #define MAXSTACK (4096 / sizeof(formula::FormulaToken*))
58 class ScTokenStack
60 public:
61 DECL_FIXEDMEMPOOL_NEWDEL( ScTokenStack )
62 formula::FormulaToken* pPointer[ MAXSTACK ];
65 enum ScIterFunc {
66 ifSUM, // Add up
67 ifSUMSQ, // Sums of squares
68 ifPRODUCT, // Product
69 ifAVERAGE, // Average
70 ifCOUNT, // Count Values
71 ifCOUNT2, // Count Values (not empty)
72 ifMIN, // Minimum
73 ifMAX // Maximum
76 enum ScIterFuncIf
78 ifSUMIF, // Conditional sum
79 ifAVERAGEIF // Conditional average
82 enum ScIterFuncIfs
84 ifSUMIFS, // Multi-Conditional sum
85 ifAVERAGEIFS, // Multi-Conditional average
86 ifCOUNTIFS // Multi-Conditional count
89 struct FormulaTokenRef_less
91 bool operator () ( const formula::FormulaConstTokenRef& r1, const formula::FormulaConstTokenRef& r2 ) const
92 { return r1.get() < r2.get(); }
94 typedef ::std::map< const formula::FormulaConstTokenRef, formula::FormulaTokenRef, FormulaTokenRef_less> ScTokenMatrixMap;
96 class ScInterpreter
98 // distibution function objects need the GetxxxDist methods
99 friend class ScGammaDistFunction;
100 friend class ScBetaDistFunction;
101 friend class ScTDistFunction;
102 friend class ScFDistFunction;
103 friend class ScChiDistFunction;
104 friend class ScChiSqDistFunction;
106 public:
107 DECL_FIXEDMEMPOOL_NEWDEL( ScInterpreter )
109 static void SetGlobalConfig(const ScCalcConfig& rConfig);
110 static const ScCalcConfig& GetGlobalConfig();
112 static void GlobalExit(); // called by ScGlobal::Clear()
114 /// Could string be a regular expression?
115 /// If pDoc!=NULL the document options are taken into account and if
116 /// RegularExpressions are disabled the function returns false regardless
117 /// of the string content.
118 static bool MayBeRegExp( const OUString& rStr, const ScDocument* pDoc );
120 /// Fail safe division, returning an errDivisionByZero coded into a double
121 /// if denominator is 0.0
122 static inline double div( const double& fNumerator, const double& fDenominator );
124 ScMatrixRef GetNewMat(SCSIZE nC, SCSIZE nR, bool bEmpty = false);
126 enum VolatileType {
127 VOLATILE,
128 VOLATILE_MACRO,
129 NOT_VOLATILE
132 VolatileType GetVolatileType() const;
134 private:
135 static ScCalcConfig maGlobalConfig;
137 static ScTokenStack* pGlobalStack;
138 static bool bGlobalStackInUse;
140 formula::FormulaTokenIterator aCode;
141 ScAddress aPos;
142 ScTokenArray& rArr;
143 ScDocument* pDok;
144 formula::FormulaTokenRef xResult;
145 ScJumpMatrix* pJumpMatrix; // currently active array condition, if any
146 ScTokenMatrixMap* pTokenMatrixMap; // map ScToken* to formula::FormulaTokenRef if in array condition
147 ScFormulaCell* pMyFormulaCell; // the cell of this formula expression
148 SvNumberFormatter* pFormatter;
150 const formula::FormulaToken*
151 pCur; // current token
152 OUString aTempStr; // for GetString()
153 ScTokenStack* pStackObj; // contains the stacks
154 formula::FormulaToken** pStack; // the current stack
155 sal_uInt16 nGlobalError; // global (local to this formula expression) error
156 sal_uInt16 sp; // stack pointer
157 sal_uInt16 maxsp; // the maximal used stack pointer
158 sal_uLong nFuncFmtIndex; // NumberFormatIndex of a function
159 sal_uLong nCurFmtIndex; // current NumberFormatIndex
160 sal_uLong nRetFmtIndex; // NumberFormatIndex of an expression, if any
161 short nFuncFmtType; // NumberFormatType of a function
162 short nCurFmtType; // current NumberFormatType
163 short nRetFmtType; // NumberFormatType of an expression
164 sal_uInt16 mnStringNoValueError; // the error set in ConvertStringToValue() if no value
165 bool glSubTotal; // flag for subtotal functions
166 sal_uInt8 cPar; // current count of parameters
167 bool bCalcAsShown; // precision as shown
168 bool bMatrixFormula; // formula cell is a matrix formula
170 VolatileType meVolatileType;
172 // nMust <= nAct <= nMax ? ok : PushError
173 inline bool MustHaveParamCount( short nAct, short nMust );
174 inline bool MustHaveParamCount( short nAct, short nMust, short nMax );
175 inline bool MustHaveParamCountMin( short nAct, short nMin );
176 void PushParameterExpected();
177 void PushIllegalParameter();
178 void PushIllegalArgument();
179 void PushNoValue();
180 void PushNA();
182 // Functions for accessing a document
184 void ReplaceCell( ScAddress& ); // for TableOp
185 void ReplaceCell( SCCOL& rCol, SCROW& rRow, SCTAB& rTab ); // for TableOp
186 bool IsTableOpInRange( const ScRange& );
187 sal_uLong GetCellNumberFormat( const ScAddress& rPos, ScRefCellValue& rCell );
188 double ConvertStringToValue( const String& );
189 double GetCellValue( const ScAddress&, ScRefCellValue& rCell );
190 double GetCellValueOrZero( const ScAddress&, ScRefCellValue& rCell );
191 double GetValueCellValue( const ScAddress&, double fOrig );
192 void GetCellString( OUString& rStr, ScRefCellValue& rCell );
193 sal_uInt16 GetCellErrCode( const ScRefCellValue& rCell );
195 bool CreateDoubleArr(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
196 SCCOL nCol2, SCROW nRow2, SCTAB nTab2, sal_uInt8* pCellArr);
197 bool CreateStringArr(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
198 SCCOL nCol2, SCROW nRow2, SCTAB nTab2, sal_uInt8* pCellArr);
199 bool CreateCellArr(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
200 SCCOL nCol2, SCROW nRow2, SCTAB nTab2, sal_uInt8* pCellArr);
202 // Stack operations
204 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
205 passed is not formula::FormulaErrorToken.
206 Increments RefCount of the original token if not substituted. */
207 void Push( formula::FormulaToken& r );
209 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
210 Used to push RPN tokens or from within Push() or tokens that are already
211 explicit formula::FormulaErrorToken. Increments RefCount. */
212 void PushWithoutError( formula::FormulaToken& r );
214 /** Clones the token to be pushed or substitutes with formula::FormulaErrorToken if
215 nGlobalError is set and the token passed is not formula::FormulaErrorToken. */
216 void PushTempToken( const formula::FormulaToken& );
218 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
219 passed is not formula::FormulaErrorToken.
220 Increments RefCount of the original token if not substituted.
221 ATTENTION! The token had to be allocated with `new' and must not be used
222 after this call if no RefCount was set because possibly it gets immediately
223 deleted in case of an errStackOverflow or if substituted with formula::FormulaErrorToken! */
224 void PushTempToken( formula::FormulaToken* );
226 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
227 Used to push tokens from within PushTempToken() or tokens that are already
228 explicit formula::FormulaErrorToken. Increments RefCount.
229 ATTENTION! The token had to be allocated with `new' and must not be used
230 after this call if no RefCount was set because possibly it gets immediately
231 decremented again and thus deleted in case of an errStackOverflow! */
232 void PushTempTokenWithoutError( formula::FormulaToken* );
234 /** If nGlobalError is set push formula::FormulaErrorToken.
235 If nGlobalError is not set do nothing.
236 Used in PushTempToken() and alike to simplify handling.
237 @return: <TRUE/> if nGlobalError. */
238 inline bool IfErrorPushError()
240 if (nGlobalError)
242 PushTempTokenWithoutError( new formula::FormulaErrorToken( nGlobalError));
243 return true;
245 return false;
248 /** Obtain cell result / content from address and push as temp token.
249 bDisplayEmptyAsString is passed to ScEmptyCell in case of an empty cell
250 result. Also obtain number format and type if _both_, type and index
251 pointer, are not NULL. */
252 void PushCellResultToken( bool bDisplayEmptyAsString, const ScAddress & rAddress,
253 short * pRetTypeExpr, sal_uLong * pRetIndexExpr );
255 formula::FormulaTokenRef PopToken();
256 void Pop();
257 void PopError();
258 double PopDouble();
259 const OUString& PopString();
260 void ValidateRef( const ScSingleRefData & rRef );
261 void ValidateRef( const ScComplexRefData & rRef );
262 void ValidateRef( const ScRefList & rRefList );
263 void SingleRefToVars( const ScSingleRefData & rRef, SCCOL & rCol, SCROW & rRow, SCTAB & rTab );
264 void PopSingleRef( ScAddress& );
265 void PopSingleRef(SCCOL& rCol, SCROW &rRow, SCTAB& rTab);
266 void DoubleRefToRange( const ScComplexRefData&, ScRange&, bool bDontCheckForTableOp = false );
267 /** If formula::StackVar formula::svDoubleRef pop ScDoubleRefToken and return values of
268 ScComplexRefData.
269 Else if StackVar svRefList return values of the ScComplexRefData where
270 rRefInList is pointing to. rRefInList is incremented. If rRefInList was the
271 last element in list pop ScRefListToken and set rRefInList to 0, else
272 rParam is incremented (!) to allow usage as in
273 while(nParamCount--) PopDoubleRef(aRange,nParamCount,nRefInList);
275 void PopDoubleRef( ScRange & rRange, short & rParam, size_t & rRefInList );
276 void PopDoubleRef( ScRange&, bool bDontCheckForTableOp = false );
277 void DoubleRefToVars( const ScToken* p,
278 SCCOL& rCol1, SCROW &rRow1, SCTAB& rTab1,
279 SCCOL& rCol2, SCROW &rRow2, SCTAB& rTab2,
280 bool bDontCheckForTableOp = false );
281 ScDBRangeBase* PopDBDoubleRef();
282 void PopDoubleRef(SCCOL& rCol1, SCROW &rRow1, SCTAB& rTab1,
283 SCCOL& rCol2, SCROW &rRow2, SCTAB& rTab2,
284 bool bDontCheckForTableOp = false );
285 void PopExternalSingleRef(sal_uInt16& rFileId, String& rTabName, ScSingleRefData& rRef);
286 void PopExternalSingleRef(ScExternalRefCache::TokenRef& rToken, ScExternalRefCache::CellFormat* pFmt = NULL);
287 void PopExternalSingleRef(sal_uInt16& rFileId, String& rTabName, ScSingleRefData& rRef,
288 ScExternalRefCache::TokenRef& rToken, ScExternalRefCache::CellFormat* pFmt = NULL);
289 void PopExternalDoubleRef(sal_uInt16& rFileId, String& rTabName, ScComplexRefData& rRef);
290 void PopExternalDoubleRef(ScExternalRefCache::TokenArrayRef& rArray);
291 void PopExternalDoubleRef(ScMatrixRef& rMat);
292 void GetExternalDoubleRef(sal_uInt16 nFileId, const String& rTabName, const ScComplexRefData& aData, ScExternalRefCache::TokenArrayRef& rArray);
293 bool PopDoubleRefOrSingleRef( ScAddress& rAdr );
294 void PopDoubleRefPushMatrix();
295 // If MatrixFormula: convert formula::svDoubleRef to svMatrix, create JumpMatrix.
296 // Else convert area reference parameters marked as ForceArray to array.
297 // Returns true if JumpMatrix created.
298 bool ConvertMatrixParameters();
299 inline void MatrixDoubleRefToMatrix(); // if MatrixFormula: PopDoubleRefPushMatrix
300 // If MatrixFormula or ForceArray: ConvertMatrixParameters()
301 inline bool MatrixParameterConversion();
302 ScMatrixRef PopMatrix();
303 void QueryMatrixType(ScMatrixRef& xMat, short& rRetTypeExpr, sal_uLong& rRetIndexExpr);
305 void PushDouble(double nVal);
306 void PushInt( int nVal );
307 void PushStringBuffer( const sal_Unicode* pString );
308 void PushString( const String& rString );
309 void PushSingleRef(SCCOL nCol, SCROW nRow, SCTAB nTab);
310 void PushDoubleRef(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
311 SCCOL nCol2, SCROW nRow2, SCTAB nTab2);
312 void PushExternalSingleRef(sal_uInt16 nFileId, const String& rTabName,
313 SCCOL nCol, SCROW nRow, SCTAB nTab);
314 void PushExternalDoubleRef(sal_uInt16 nFileId, const String& rTabName,
315 SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
316 SCCOL nCol2, SCROW nRow2, SCTAB nTab2);
317 void PushMatrix(const ScMatrixRef& pMat);
318 void PushError( sal_uInt16 nError );
319 /// Raw stack type without default replacements.
320 formula::StackVar GetRawStackType();
321 /// Stack type with replacement of defaults, e.g. svMissing and formula::svEmptyCell will result in formula::svDouble.
322 formula::StackVar GetStackType();
323 // peek StackType of Parameter, Parameter 1 == TOS, 2 == TOS-1, ...
324 formula::StackVar GetStackType( sal_uInt8 nParam );
325 sal_uInt8 GetByte() { return cPar; }
326 // generates a position-dependent SingleRef out of a DoubleRef
327 bool DoubleRefToPosSingleRef( const ScRange& rRange, ScAddress& rAdr );
328 double GetDoubleFromMatrix(const ScMatrixRef& pMat);
329 double GetDouble();
330 double GetDoubleWithDefault(double nDefault);
331 bool IsMissing();
332 bool GetBool() { return GetDouble() != 0.0; }
333 const OUString& GetString();
334 const OUString& GetStringFromMatrix(const ScMatrixRef& pMat);
335 // pop matrix and obtain one element, upper left or according to jump matrix
336 ScMatValType GetDoubleOrStringFromMatrix( double& rDouble, OUString& rString );
337 ScMatrixRef CreateMatrixFromDoubleRef( const formula::FormulaToken* pToken,
338 SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
339 SCCOL nCol2, SCROW nRow2, SCTAB nTab2 );
340 inline ScTokenMatrixMap& GetTokenMatrixMap();
341 ScTokenMatrixMap* CreateTokenMatrixMap();
342 ScMatrixRef GetMatrix();
343 void ScTableOp(); // repeated operations
344 void ScErrCell(); // special handling for
345 // error cell
347 // common helper functions
349 void SetMaxIterationCount(sal_uInt16 n);
350 inline void CurFmtToFuncFmt()
351 { nFuncFmtType = nCurFmtType; nFuncFmtIndex = nCurFmtIndex; }
352 // Check for String overflow of rResult+rAdd and set error and erase rResult
353 // if so. Return true if ok, false if overflow
354 inline bool CheckStringResultLen( String& rResult, const String& rAdd );
355 // Set error according to rVal, and set rVal to 0.0 if there was an error.
356 inline void TreatDoubleError( double& rVal );
357 // Lookup using ScLookupCache, @returns true if found and result address
358 bool LookupQueryWithCache( ScAddress & o_rResultPos,
359 const ScQueryParam & rParam ) const;
361 void ScIfJump();
362 void ScIfError( bool bNAonly );
363 void ScChoseJump();
365 // Be sure to only call this if pStack[sp-nStackLevel] really contains a
366 // ScJumpMatrixToken, no further checks are applied!
367 // Returns true if last jump was executed and result matrix pushed.
368 bool JumpMatrix( short nStackLevel );
370 /** @param pOptions
371 NULL means case sensitivity document option is to be used!
373 double CompareFunc( const ScCompare& rComp, ScCompareOptions* pOptions = NULL );
374 double Compare();
375 /** @param pOptions
376 NULL means case sensitivity document option is to be used!
378 ScMatrixRef CompareMat( ScCompareOptions* pOptions = NULL );
379 ScMatrixRef QueryMat( const ScMatrixRef& pMat, ScCompareOptions& rOptions );
380 void ScEqual();
381 void ScNotEqual();
382 void ScLess();
383 void ScGreater();
384 void ScLessEqual();
385 void ScGreaterEqual();
386 void ScAnd();
387 void ScOr();
388 void ScXor();
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 ScCellExternal();
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 ScNumberValue();
455 void ScClean();
456 void ScChar();
457 void ScJis();
458 void ScAsc();
459 void ScUnicode();
460 void ScUnichar();
461 void ScMin( bool bTextAsZero = false );
462 void ScMax( bool bTextAsZero = false );
463 double IterateParameters( ScIterFunc, bool bTextAsZero = false );
464 void ScSumSQ();
465 void ScSum();
466 void ScProduct();
467 void ScAverage( bool bTextAsZero = false );
468 void ScCount();
469 void ScCount2();
470 void GetStVarParams( double& rVal, double& rValCount, bool bTextAsZero = false );
471 void ScVar( bool bTextAsZero = false );
472 void ScVarP( bool bTextAsZero = false );
473 void ScStDev( bool bTextAsZero = false );
474 void ScStDevP( bool bTextAsZero = false );
475 void ScColumns();
476 void ScRows();
477 void ScTables();
478 void ScColumn();
479 void ScRow();
480 void ScTable();
481 void ScMatch();
482 double IterateParametersIf( ScIterFuncIf );
483 void ScCountIf();
484 void ScSumIf();
485 void ScAverageIf();
486 double IterateParametersIfs( ScIterFuncIfs );
487 void ScSumIfs();
488 void ScAverageIfs();
489 void ScCountIfs();
490 void ScCountEmptyCells();
491 void ScLookup();
492 void ScHLookup();
493 void ScVLookup();
494 void ScSubTotal();
496 // If upon call rMissingField==true then the database field parameter may be
497 // missing (Xcl DCOUNT() syntax), or may be faked as missing by having the
498 // value 0.0 or being exactly the entire database range reference (old SO
499 // compatibility). If this was the case then rMissingField is set to true upon
500 // return. If rMissingField==false upon call all "missing cases" are considered
501 // to be an error.
502 ScDBQueryParamBase* GetDBParams( bool& rMissingField );
504 void DBIterator( ScIterFunc );
505 void ScDBSum();
506 void ScDBCount();
507 void ScDBCount2();
508 void ScDBAverage();
509 void ScDBGet();
510 void ScDBMax();
511 void ScDBMin();
512 void ScDBProduct();
513 void GetDBStVarParams( double& rVal, double& rValCount );
514 void ScDBStdDev();
515 void ScDBStdDevP();
516 void ScDBVar();
517 void ScDBVarP();
518 void ScIndirect();
519 void ScAddressFunc();
520 void ScOffset();
521 void ScIndex();
522 void ScMultiArea();
523 void ScAreas();
524 void ScCurrency();
525 void ScReplace();
526 void ScFixed();
527 void ScFind();
528 void ScExact();
529 void ScLeft();
530 void ScRight();
531 void ScSearch();
532 void ScMid();
533 void ScText();
534 void ScSubstitute();
535 void ScRept();
536 void ScConcat();
537 void ScExternal();
538 void ScMissing();
539 void ScMacro();
540 bool SetSbxVariable( SbxVariable* pVar, const ScAddress& );
541 bool SetSbxVariable( SbxVariable* pVar, SCCOL nCol, SCROW nRow, SCTAB nTab );
542 void ScErrorType();
543 void ScDBArea();
544 void ScColRowNameAuto();
545 void ScGetPivotData();
546 void ScHyperLink();
547 void ScBahtText();
548 void ScBitAnd();
549 void ScBitOr();
550 void ScBitXor();
551 void ScBitRshift();
552 void ScBitLshift();
553 void ScTTT();
555 /** Obtain the date serial number for a given date.
556 @param bStrict
557 If false, nYear < 100 takes the two-digit year setting into account,
558 and rollover of invalid calendar dates takes place, e.g. 1999-02-31 =>
559 1999-03-03.
560 If true, the date passed must be a valid Gregorian calendar date. No
561 two-digit expanding or rollover is done.
563 @param bCheckGregorian
564 If true, date must be Gregorian, i.e. >= 1582-10-15.
565 If false, don't care, any valid date >= 0-1-1 will do.
567 double GetDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, bool bStrict, bool bCheckGregorian );
569 void ScGetActDate();
570 void ScGetActTime();
571 void ScGetYear();
572 void ScGetMonth();
573 void ScGetDay();
574 void ScGetDayOfWeek();
575 void ScGetWeekOfYear();
576 void ScEasterSunday();
577 void ScGetHour();
578 void ScGetMin();
579 void ScGetSec();
580 void ScPlusMinus();
581 void ScAbs();
582 void ScInt();
583 void ScEven();
584 void ScOdd();
585 void ScCeil();
586 void ScFloor();
587 void RoundNumber( rtl_math_RoundingMode eMode );
588 void ScRound();
589 void ScRoundUp();
590 void ScRoundDown();
591 void ScGetDateValue();
592 void ScGetTimeValue();
593 void ScArcTan2();
594 void ScLog();
595 void ScGetDate();
596 void ScGetTime();
597 void ScGetDiffDate();
598 void ScGetDiffDate360();
599 void ScGetDateDif();
600 void ScPower();
601 void ScAmpersand();
602 void ScAdd();
603 void ScSub();
604 void ScMul();
605 void ScDiv();
606 void ScPow();
607 void ScCurrent();
608 void ScStyle();
609 void ScDde();
610 void ScBase();
611 void ScDecimal();
612 void ScConvert();
613 void ScEuroConvert();
615 // financial functions
616 void ScNPV();
617 void ScIRR();
618 void ScMIRR();
619 void ScISPMT();
621 double ScGetBw(double fZins, double fZzr, double fRmz,
622 double fZw, double fF);
623 void ScBW();
624 void ScDIA();
625 double ScGetGDA(double fWert, double fRest, double fDauer,
626 double fPeriode, double fFaktor);
627 void ScGDA();
628 void ScGDA2();
629 double ScInterVDB(double fWert,double fRest,double fDauer,double fDauer1,
630 double fPeriode,double fFaktor);
631 void ScVDB();
632 void ScLaufz();
633 void ScLIA();
634 double ScGetRmz(double fZins, double fZzr, double fBw,
635 double fZw, double fF);
636 void ScRMZ();
637 void ScZGZ();
638 double ScGetZw(double fZins, double fZzr, double fRmz,
639 double fBw, double fF);
640 void ScZW();
641 void ScZZR();
642 bool RateIteration(double fNper, double fPayment, double fPv,
643 double fFv, double fPayType, double& fGuess);
644 void ScZins();
645 double ScGetZinsZ(double fZins, double fZr, double fZzr, double fBw,
646 double fZw, double fF, double& fRmz);
647 void ScZinsZ();
648 void ScKapz();
649 void ScKumZinsZ();
650 void ScKumKapZ();
651 void ScEffektiv();
652 void ScNominal();
653 void ScMod();
654 void ScIntercept();
655 double ScGetGCD(double fx, double fy);
656 void ScGCD();
657 void ScLCM();
659 // matrix functions
660 void ScMatValue();
661 void MEMat(const ScMatrixRef& mM, SCSIZE n);
662 void ScMatDet();
663 void ScMatInv();
664 void ScMatMult();
665 void ScMatTrans();
666 void ScEMat();
667 void ScMatRef();
668 ScMatrixRef MatConcat(const ScMatrixRef& pMat1, const ScMatrixRef& pMat2);
669 void ScSumProduct();
670 void ScSumX2MY2();
671 void ScSumX2DY2();
672 void ScSumXMY2();
673 void ScGrowth();
674 bool CalculateSkew(double& fSum,double& fCount,double& vSum,std::vector<double>& values);
675 void CalculateSkewOrSkewp( bool bSkewp );
676 void CalculateSlopeIntercept(bool bSlope);
677 void CalculateSmallLarge(bool bSmall);
678 void CalculatePearsonCovar(bool _bPearson,bool _bStexy);
679 bool CalculateTest( bool _bTemplin
680 ,const SCSIZE nC1, const SCSIZE nC2,const SCSIZE nR1,const SCSIZE nR2
681 ,const ScMatrixRef& pMat1,const ScMatrixRef& pMat2
682 ,double& fT,double& fF);
683 void CalculateLookup(bool HLookup);
684 bool FillEntry(ScQueryEntry& rEntry);
685 void CalculateAddSub(bool _bSub);
686 void CalculateTrendGrowth(bool _bGrowth);
687 void CalulateRGPRKP(bool _bRKP);
688 void CalculateSumX2MY2SumX2DY2(bool _bSumX2DY2);
689 void CalculateMatrixValue(const ScMatrix* pMat,SCSIZE nC,SCSIZE nR);
690 bool CheckMatrix(bool _bLOG,sal_uInt8& nCase,SCSIZE& nCX,SCSIZE& nCY,SCSIZE& nRX,SCSIZE& nRY,SCSIZE& M,SCSIZE& N,ScMatrixRef& pMatX,ScMatrixRef& pMatY);
691 void ScRGP();
692 void ScRKP();
693 void ScForecast();
694 void ScNoName();
695 void ScBadName();
696 // Statistics:
697 double phi(double x);
698 double integralPhi(double x);
699 double taylor(double* pPolynom, sal_uInt16 nMax, double x);
700 double gauss(double x);
701 double gaussinv(double x);
702 double GetBetaDist(double x, double alpha, double beta); //cumulative distribution function
703 double GetBetaDistPDF(double fX, double fA, double fB); //probability density function)
704 double GetChiDist(double fChi, double fDF); // for LEGACY.CHIDIST, returns right tail
705 double GetChiSqDistCDF(double fX, double fDF); // for CHISQDIST, returns left tail
706 double GetChiSqDistPDF(double fX, double fDF); // probability density function
707 double GetFDist(double x, double fF1, double fF2);
708 double GetTDist(double T, double fDF);
709 double Fakultaet(double x);
710 double BinomKoeff(double n, double k);
711 double GetGamma(double x);
712 double GetLogGamma(double x);
713 double GetBeta(double fAlpha, double fBeta);
714 double GetLogBeta(double fAlpha, double fBeta);
715 double GetBinomDistPMF(double x, double n, double p); //probability mass function
716 void ScLogGamma();
717 void ScGamma();
718 void ScPhi();
719 void ScGauss();
720 void ScStdNormDist();
721 void ScFisher();
722 void ScFisherInv();
723 void ScFact();
724 void ScNormDist();
725 void ScGammaDist();
726 void ScGammaInv();
727 void ScExpDist();
728 void ScBinomDist();
729 void ScPoissonDist();
730 void ScKombin();
731 void ScKombin2();
732 void ScVariationen();
733 void ScVariationen2();
734 void ScB();
735 void ScHypGeomDist();
736 void ScLogNormDist();
737 void ScLogNormInv();
738 void ScTDist();
739 void ScFDist();
740 void ScChiDist(); // for LEGACY.CHIDIST, returns right tail
741 void ScChiSqDist(); // returns left tail or density
742 void ScChiSqInv(); //invers to CHISQDIST
743 void ScWeibull();
744 void ScBetaDist();
745 void ScFInv();
746 void ScTInv();
747 void ScChiInv();
748 void ScBetaInv();
749 void ScCritBinom();
750 void ScNegBinomDist();
751 void ScKurt();
752 void ScHarMean();
753 void ScGeoMean();
754 void ScStandard();
755 void ScSkew();
756 void ScSkewp();
757 void ScMedian();
758 double GetMedian( ::std::vector<double> & rArray );
759 double GetPercentile( ::std::vector<double> & rArray, double fPercentile );
760 void GetNumberSequenceArray( sal_uInt8 nParamCount, ::std::vector<double>& rArray );
761 void GetSortArray(sal_uInt8 nParamCount, ::std::vector<double>& rSortArray, ::std::vector<long>* pIndexOrder = NULL);
762 void QuickSort(::std::vector<double>& rSortArray, ::std::vector<long>* pIndexOrder = NULL);
763 void ScModalValue();
764 void ScAveDev();
765 void ScDevSq();
766 void ScZTest();
767 void ScTTest();
768 void ScFTest();
769 void ScChiTest();
770 void ScRank();
771 void ScPercentile();
772 void ScPercentrank();
773 void ScLarge();
774 void ScSmall();
775 void ScFrequency();
776 void ScQuartile();
777 void ScNormInv();
778 void ScSNormInv();
779 void ScConfidence();
780 void ScTrimMean();
781 void ScProbability();
782 void ScCorrel();
783 void ScCovar();
784 void ScPearson();
785 void ScRSQ();
786 void ScSTEXY();
787 void ScSlope();
788 void ScTrend();
789 void ScInfo();
791 static const double fMaxGammaArgument;
793 double GetGammaContFraction(double fA,double fX);
794 double GetGammaSeries(double fA,double fX);
795 double GetLowRegIGamma(double fA,double fX); // lower regularized incomplete gamma function, GAMMAQ
796 double GetUpRegIGamma(double fA,double fX); // upper regularized incomplete gamma function, GAMMAP
797 // probability density function; fLambda is "scale" parameter
798 double GetGammaDistPDF(double fX, double fAlpha, double fLambda);
799 // cumulative distribution function; fLambda is "scale" parameter
800 double GetGammaDist(double fX, double fAlpha, double fLambda);
802 public:
803 ScInterpreter( ScFormulaCell* pCell, ScDocument* pDoc,
804 const ScAddress&, ScTokenArray& );
805 ~ScInterpreter();
807 formula::StackVar Interpret();
809 void SetError(sal_uInt16 nError)
810 { if (nError && !nGlobalError) nGlobalError = nError; }
812 sal_uInt16 GetError() const { return nGlobalError; }
813 formula::StackVar GetResultType() const { return xResult->GetType(); }
814 const String& GetStringResult() const { return xResult->GetString(); }
815 double GetNumResult() const { return xResult->GetDouble(); }
816 formula::FormulaTokenRef GetResultToken() const { return xResult; }
817 short GetRetFormatType() const { return nRetFmtType; }
818 sal_uLong GetRetFormatIndex() const { return nRetFmtIndex; }
821 inline void ScInterpreter::MatrixDoubleRefToMatrix()
823 if ( bMatrixFormula && GetStackType() == formula::svDoubleRef )
825 GetTokenMatrixMap(); // make sure it exists, create if not.
826 PopDoubleRefPushMatrix();
830 inline bool ScInterpreter::MatrixParameterConversion()
832 if ( (bMatrixFormula || pCur->HasForceArray()) && !pJumpMatrix && sp > 0 )
833 return ConvertMatrixParameters();
834 return false;
837 inline ScTokenMatrixMap& ScInterpreter::GetTokenMatrixMap()
839 if (!pTokenMatrixMap)
840 pTokenMatrixMap = CreateTokenMatrixMap();
841 return *pTokenMatrixMap;
844 inline bool ScInterpreter::MustHaveParamCount( short nAct, short nMust )
846 if ( nAct == nMust )
847 return true;
848 if ( nAct < nMust )
849 PushParameterExpected();
850 else
851 PushIllegalParameter();
852 return false;
855 inline bool ScInterpreter::MustHaveParamCount( short nAct, short nMust, short nMax )
857 if ( nMust <= nAct && nAct <= nMax )
858 return true;
859 if ( nAct < nMust )
860 PushParameterExpected();
861 else
862 PushIllegalParameter();
863 return false;
866 inline bool ScInterpreter::MustHaveParamCountMin( short nAct, short nMin )
868 if ( nAct >= nMin )
869 return true;
870 PushParameterExpected();
871 return false;
874 inline bool ScInterpreter::CheckStringResultLen( String& rResult, const String& rAdd )
876 if ( (sal_uLong) rResult.Len() + rAdd.Len() > STRING_MAXLEN )
878 SetError( errStringOverflow );
879 rResult.Erase();
880 return false;
882 return true;
885 inline void ScInterpreter::TreatDoubleError( double& rVal )
887 if ( !::rtl::math::isFinite( rVal ) )
889 sal_uInt16 nErr = GetDoubleErrorValue( rVal );
890 if ( nErr )
891 SetError( nErr );
892 else
893 SetError( errNoValue );
894 rVal = 0.0;
898 inline double ScInterpreter::div( const double& fNumerator, const double& fDenominator )
900 return (fDenominator != 0.0) ? (fNumerator / fDenominator) :
901 CreateDoubleError( errDivisionByZero);
904 #endif
906 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */