From 93825921ef600413f35eeaf53203415bec85cd7a Mon Sep 17 00:00:00 2001 From: oetiker Date: Wed, 14 Feb 2007 18:54:29 +0000 Subject: [PATCH] new operator ABS added -- git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@1008 a5681a0c-68f1-0310-ab6d-d61299d08faa --- doc/rrdgraph_rpn.pod | 4 ++++ src/rrd_rpncalc.c | 6 ++++++ src/rrd_rpncalc.h | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/rrdgraph_rpn.pod b/doc/rrdgraph_rpn.pod index 6e31ea6..b2a84dd 100644 --- a/doc/rrdgraph_rpn.pod +++ b/doc/rrdgraph_rpn.pod @@ -127,6 +127,10 @@ B Convert angle in degrees to radians, or radians to degrees. +B + +Take the absolute value. + =item Set Operations B diff --git a/src/rrd_rpncalc.c b/src/rrd_rpncalc.c index a5ab61f..972f486 100644 --- a/src/rrd_rpncalc.c +++ b/src/rrd_rpncalc.c @@ -162,6 +162,7 @@ void rpn_compact2str(rpn_cdefds_t *rpnc,ds_def_t *ds_def,char **str) add_op(OP_RAD2DEG,RAD2DEG) add_op(OP_DEG2RAD,DEG2RAD) add_op(OP_AVG,AVG) + add_op(OP_ABS,ABS) #undef add_op } (*str)[offset] = '\0'; @@ -340,6 +341,7 @@ rpn_parse(void *key_hash,const char *const expr_const,long (*lookup)(void *,char match_op(OP_RAD2DEG,RAD2DEG) match_op(OP_DEG2RAD,DEG2RAD) match_op(OP_AVG,AVG) + match_op(OP_ABS,ABS) #undef match_op @@ -779,6 +781,10 @@ rpn_calc(rpnp_t *rpnp, rpnstack_t *rpnstack, long data_idx, } } break; + case OP_ABS: + stackunderflow(0); + rpnstack -> s[stptr] = fabs(rpnstack -> s[stptr]); + break; case OP_END: break; } diff --git a/src/rrd_rpncalc.h b/src/rrd_rpncalc.h index beccfd5..3575808 100644 --- a/src/rrd_rpncalc.h +++ b/src/rrd_rpncalc.h @@ -18,7 +18,7 @@ enum op_en {OP_NUMBER=0,OP_VARIABLE,OP_INF,OP_PREV,OP_NEGINF, 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_AVG}; + OP_AVG,OP_ABS}; typedef struct rpnp_t { enum op_en op; -- 2.11.0