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