Changeset 2598 in Sophya for trunk/SophyaLib/SysTools/rpneval.cc
- Timestamp:
- Aug 11, 2004, 3:10:25 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SysTools/rpneval.cc
r2596 r2598 10 10 11 11 /*! 12 \class SOPHYA::RPNExpressionEvaluator12 \class RPNExpressionEvaluator 13 13 \ingroup SysTools 14 14 Arithmetic expression (double precision float) evaluator 15 15 in Reverse Polish Notation (RPN). This is an HP calculator 16 16 like syntax. Space are used for separating the string 17 expression into tokens. 17 expression into tokens. \n 18 The string parsed by RPNExpressionEvaluator should be 19 formed by a set of space separated words. Each word may be 20 a numerical constant or operation or function. 21 All numeriacl constants are pushed to stack top. 22 The stack is limited only 23 by the available memory. The three numbers on the stack top 24 are referred to as <tt> x y x </tt>. \n 25 Available operations: 26 - op= + - * / % : replace (x,y) by x.op.y 27 - e pi : M_PI , M_E numerical constants 28 - f= sin cos tan asin acos atan : replace x by f(x) 29 - f= chs sqrt sq : (x<-f(x)) change-sign , square root and square (x<-x^2) operations 30 - f= log log10 exp : replace x by f(x) 31 - f= fabs floor ceiling : replace x by f(x) 32 - f= deg2rad rad2deg : replace x by f(x) 33 - f= rand01 randpm1 gaurand : pushes a random number on the stack top ([0 1] [-1 1] Gaussian) 34 - print x<>y pop push : stack operations 35 - sum product : Replace the complete stack by the sum / product of the numbers in the stack 36 - mean sigma : Replace the complete stack by the mean / sigma of the numbers in the stack 37 38 \sa CExpressionEvaluator Commander 39 40 The following output is produced by the sample code below: 41 \code 42 #include "rpneval.h" 43 ... 44 RPNExpressionEvaluator rpn1("4 2 print + 3 * "); 45 cout << "RPN1: 4 2 + 3 * -> rpn1.Value() = " << rpn1.Value() << endl; 46 RPNExpressionEvaluator rpn2("1 2 3 4 5 sum"); 47 cout << "RPN2: 1 2 3 4 5 sum -> rpn2.Value() = " << rpn2.Value() << endl; 48 \endcode 49 50 Output: 51 \verbatim 52 RPNExpressionEvaluator::PrintStack() Size()= 2 53 0: 2 (x) 54 1: 4 (y) 55 RPN1: 4 2 + 3 * -> rpn1.Value() = 18 56 RPN2: 1 2 3 4 5 sum -> rpn2.Value() = 15 57 \endverbatim 18 58 */ 19 59 60 /*! 61 \brief Parses the string \b sex into words and perform the specified operations on the stack. 62 63 Can throw RPNExprException 64 */ 20 65 RPNExpressionEvaluator::RPNExpressionEvaluator(string const & sex) 21 66 { … … 33 78 } 34 79 80 /*! 81 \brief Perform the operations specified by \b on the stack, starting from element \b exe[off]. 82 83 Can throw RPNExprException 84 */ 35 85 RPNExpressionEvaluator::RPNExpressionEvaluator(vector<string> & exe, int off) 36 86 { … … 52 102 /* Operations sur le stack RPN */ 53 103 /* --Methode-- */ 104 //! Return the stack top (x) 54 105 double RPNExpressionEvaluator::Evaluate() const 55 106 {
Note:
See TracChangeset
for help on using the changeset viewer.