compute the average of the values v1 to v6 after removing the smallest and
largest.
+B<AVG>
+
+Pop one element (I<count>) from the stack. Now pop I<count> elements and build the
+average, ignoring all UNKNOWN values in the process.
+
+Example: C<CDEF:x=a,b,c,d,4,AVG>
+
B<TREND>
Create a "sliding window" average of another data series.
add_op(OP_TREND,TREND)
add_op(OP_RAD2DEG,RAD2DEG)
add_op(OP_DEG2RAD,DEG2RAD)
+ add_op(OP_AVG,AVG)
#undef add_op
}
(*str)[offset] = '\0';
match_op(OP_TREND,TREND)
match_op(OP_RAD2DEG,RAD2DEG)
match_op(OP_DEG2RAD,DEG2RAD)
+ match_op(OP_AVG,AVG)
#undef match_op
rpnstack -> s[--stptr] = DNAN;
}
break;
+ case OP_AVG:
+ stackunderflow(0);
+ {
+ int i=rpnstack -> s[stptr--];
+ double sum=0;
+ int count=0;
+ stackunderflow(i-1);
+ while(i>0) {
+ double val=rpnstack -> s[stptr--];
+ i--;
+ if (isnan(val)) { continue; }
+ count++;
+ sum+=val;
+ }
+ // now push the result bavk on stack
+ if (count>0) {
+ rpnstack -> s[++stptr]=sum/count;
+ } else {
+ rpnstack -> s[++stptr]=DNAN;
+ }
+ }
+ break;
case OP_END:
break;
}
OP_MIN,OP_MAX,OP_LIMIT, OP_FLOOR, OP_CEIL,
OP_UN,OP_END,OP_LTIME,OP_NE,OP_ISINF,OP_PREV_OTHER,OP_COUNT,
OP_ATAN,OP_SQRT,OP_SORT,OP_REV,OP_TREND,
- OP_ATAN2,OP_RAD2DEG,OP_DEG2RAD};
+ OP_ATAN2,OP_RAD2DEG,OP_DEG2RAD,
+ OP_AVG};
typedef struct rpnp_t {
enum op_en op;