/****************************************************************************
- * RRDtool 1.2.13 Copyright by Tobi Oetiker, 1997-2006
+ * RRDtool 1.2.15 Copyright by Tobi Oetiker, 1997-2006
****************************************************************************
* rrd_rpncalc.c RPN calculator functions
****************************************************************************/
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;
}