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