11void RPN::evaluate_array(
double dResult[])
13 double d1[MAX_JOBS],d2[MAX_JOBS],d3[MAX_JOBS],d4[MAX_JOBS];
16 switch(m_pExpression[m_nTree][m_iPosition])
21 for(i=m_iOffset; i<m_iEnd; i++)
22 dResult[pIndex[i]] = d1[pIndex[i]] + d2[pIndex[i]];
27 for(i=m_iOffset; i<m_iEnd; i++)
28 dResult[pIndex[i]] = d1[pIndex[i]] - d2[pIndex[i]];
33 for(i=m_iOffset; i<m_iEnd; i++)
34 dResult[pIndex[i]] = d1[pIndex[i]] * d2[pIndex[i]];
39 for(i=m_iOffset; i<m_iEnd; i++)
40 {
if(fabs(d2[pIndex[i]]) < 0.000001)
41 dResult[pIndex[i]] = 1;
43 dResult[pIndex[i]] = d1[pIndex[i]] / d2[pIndex[i]];
48 for(i=m_iOffset; i<m_iEnd; i++)
50 dResult[pIndex[i]] = d1[pIndex[i]];
52 dResult[pIndex[i]] = 0;
56 for(i=m_iOffset; i<m_iEnd; i++)
57 dResult[pIndex[i]] = sin(d1[pIndex[i]]);
61 for(i=m_iOffset; i<m_iEnd; i++)
62 dResult[pIndex[i]] = cos(d1[pIndex[i]]);
66 for(i=m_iOffset; i<m_iEnd; i++)
67 if(d1[pIndex[i]] < 80.)
68 dResult[pIndex[i]] = cos(d1[pIndex[i]]);
70 dResult[pIndex[i]] = 1;
74 for(i=m_iOffset; i<m_iEnd; i++)
75 if(fabs(d1[pIndex[i]]) > 0.000001)
76 dResult[pIndex[i]] = log(fabs(d1[pIndex[i]]));
78 dResult[pIndex[i]] = 1;
82 for(i=m_iOffset; i<m_iEnd; i++)
84 dResult[pIndex[i]] = 1;
86 dResult[pIndex[i]] = sqrt(d1[pIndex[i]]);
93 for(i=m_iOffset; i<m_iEnd; i++)
94 if(d1[pIndex[i]] > d2[pIndex[i]])
95 dResult[pIndex[i]] = d3[pIndex[i]];
97 dResult[pIndex[i]] = d4[pIndex[i]];
100 memcpy(dResult, m_dTermValuesArray[m_pExpression[m_nTree][m_iPosition]], m_iArraySize*
sizeof(
double));
106double RPN::evaluate()
110 switch(m_pExpression[m_nTree][m_iPosition])
113 return evaluate() + evaluate();
116 return evaluate() - evaluate();
119 return evaluate() * evaluate();
124 if(fabs(d2) < 0.000001)
137 return m_pTermValues[m_pExpression[m_nTree][m_iPosition]];
145 uint iCurrent,iOp1,iOp2,i;
147 iCurrent = ++m_iEditedPos;
148 m_pEdited[m_iEditedPos] = m_pExpression[m_nTree][m_iPosition];
149 switch(m_pExpression[m_nTree][m_iPosition])
152 r1 = edit(); iOp1 = m_iEditedPos;
153 r2 = edit(); iOp2 = m_iEditedPos;
155 {
for(i=0; i<iOp2-iOp1; i++)
156 m_pEdited[iCurrent+i] = m_pEdited[iOp1+1+i];
157 m_iEditedPos = m_iEditedPos - (iOp1 - iCurrent) - 1;
161 {
for(i=0; i<iOp1-iCurrent; i++)
162 m_pEdited[iCurrent+i] = m_pEdited[iCurrent+i+1];
163 m_iEditedPos = m_iEditedPos - (iOp2 - iOp1) - 1;
170 r1 = edit(); iOp1 = m_iEditedPos;
171 r2 = edit(); iOp2 = m_iEditedPos;
175 if(r1<m_iTermNum && r1==r2)
177 { m_iEditedPos = iCurrent;
178 m_pEdited[m_iEditedPos] = NUL;
182 {
for(i=0; i<iOp1-iCurrent; i++)
183 m_pEdited[iCurrent+i] = m_pEdited[iCurrent+i+1];
184 m_iEditedPos = m_iEditedPos - (iOp2 - iOp1) - 1;
188 else if(r1==r2 && (iOp1-iCurrent)==(iOp2-iOp1))
189 {
for(i=0; i<iOp2-iOp1; i++)
190 if(m_pEdited[iCurrent+1+i] != m_pEdited[iOp1+1+i])
194 m_iEditedPos = iCurrent;
195 m_pEdited[m_iEditedPos] = NUL;
202 r1 = edit(); iOp1 = m_iEditedPos;
203 r2 = edit(); iOp2 = m_iEditedPos;
205 {
for(i=0; i<iOp2-iOp1; i++)
206 m_pEdited[iCurrent+i] = m_pEdited[iOp1+1+i];
207 m_iEditedPos = m_iEditedPos - (iOp1 - iCurrent) - 1;
211 {
for(i=0; i<iOp1-iCurrent; i++)
212 m_pEdited[iCurrent+i] = m_pEdited[iCurrent+i+1];
213 m_iEditedPos = m_iEditedPos - (iOp2 - iOp1) - 1;
218 else if(r1==NUL || r2==NUL)
219 { m_iEditedPos = iCurrent;
220 m_pEdited[m_iEditedPos] = NUL;
228 r1 = edit(); iOp1 = m_iEditedPos;
229 r2 = edit(); iOp2 = m_iEditedPos;
233 if(r1<m_iTermNum && r1==r2)
235 { m_iEditedPos = iCurrent;
236 m_pEdited[m_iEditedPos] = ONE;
240 else if(r1==r2 && (iOp1-iCurrent)==(iOp2-iOp1))
241 {
for(i=0; i<iOp2-iOp1; i++)
242 if(m_pEdited[iCurrent+1+i] != m_pEdited[iOp1+1+i])
246 m_iEditedPos = iCurrent;
247 m_pEdited[m_iEditedPos] = ONE;
251 { m_iEditedPos = iCurrent;
252 m_pEdited[m_iEditedPos] = ONE;
258 {
for(i=0; i<iOp1-iCurrent; i++)
259 m_pEdited[iCurrent+i] = m_pEdited[iCurrent+i+1];
260 m_iEditedPos = m_iEditedPos - (iOp2 - iOp1) - 1;
264 { m_iEditedPos = iCurrent;
265 m_pEdited[m_iEditedPos] = NUL;
276 if(r1 <= TERMINALS + OFFSET)
277 { m_iEditedPos = iCurrent;
278 m_pEdited[m_iEditedPos] = r1;
287 if(r1 == NUL || r1 == ONE)
288 { m_iEditedPos = iCurrent;
289 m_pEdited[m_iEditedPos] = r1;
303 return m_pExpression[m_nTree][m_iPosition];
313 for(
int i = 0; i<TOTAL_NODES; i++)
317 for(
int i = 0; i<m_iEditedPos+1; i++)
318 { Nodes[m_pEdited[i]].frequency++;
319 m_pNodeFreq[m_pEdited[i]] += 1;
320 m_pExpression[m_nTree][i] = m_pEdited[i];
325void RPN::ResetNodeFreq()
328 for(i = 0; i<TERMINALS+OFFSET; i++)
329 Nodes[i].frequency = 0;
330 for(i = FUNC_START; i<FUNC_END; i++)
331 Nodes[i].frequency = 0;
345 switch(m_pExpression[m_nTree][m_iPosition])
387 m_output += Nodes[m_pExpression[m_nTree][m_iPosition]].name;