From a6f5f1b6b90008e73fa57882276bc643c039bb09 Mon Sep 17 00:00:00 2001 From: oetiker Date: Sun, 5 Jun 2005 22:23:32 +0000 Subject: [PATCH] New functions for CDEF ATAN2 RAD2DEG and DEG2RAD -- Simon Melhuish git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@610 a5681a0c-68f1-0310-ab6d-d61299d08faa --- doc/rrdgraph_rpn.pod | 15 ++++++++++++++- src/rrd_rpncalc.c | 21 +++++++++++++++++++++ src/rrd_rpncalc.h | 3 ++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/doc/rrdgraph_rpn.pod b/doc/rrdgraph_rpn.pod index 4585850..74ac4ad 100644 --- a/doc/rrdgraph_rpn.pod +++ b/doc/rrdgraph_rpn.pod @@ -107,11 +107,24 @@ B Arctangent (output in radians). +B + +Arctangent of y,x components (output in radians). +This pops one element from the stack, the x (cosine) component, and then +a second, which is the y (sine) component. +It then pushes the arctangent of their ratio, resolving the ambiguity between +quadrants. + +Example: C will convert C +components into an angle in degrees. + B Round down or up to the nearest integer. -Z<> +B + +Convert angle in degrees to radians, or radians to degrees. =item Set Operations diff --git a/src/rrd_rpncalc.c b/src/rrd_rpncalc.c index 1fd30aa..688becc 100644 --- a/src/rrd_rpncalc.c +++ b/src/rrd_rpncalc.c @@ -153,11 +153,14 @@ void rpn_compact2str(rpn_cdefds_t *rpnc,ds_def_t *ds_def,char **str) add_op(OP_NOW,NOW) add_op(OP_LTIME,LTIME) add_op(OP_TIME,TIME) + add_op(OP_ATAN2,ATAN2) add_op(OP_ATAN,ATAN) add_op(OP_SQRT,SQRT) add_op(OP_SORT,SORT) add_op(OP_REV,REV) add_op(OP_TREND,TREND) + add_op(OP_RAD2DEG,RAD2DEG) + add_op(OP_DEG2RAD,DEG2RAD) #undef add_op } (*str)[offset] = '\0'; @@ -325,11 +328,14 @@ rpn_parse(void *key_hash,char *expr,long (*lookup)(void *,char*)){ match_op(OP_ISINF,ISINF) match_op(OP_NOW,NOW) match_op(OP_TIME,TIME) + match_op(OP_ATAN2,ATAN2) match_op(OP_ATAN,ATAN) match_op(OP_SQRT,SQRT) match_op(OP_SORT,SORT) match_op(OP_REV,REV) match_op(OP_TREND,TREND) + match_op(OP_RAD2DEG,RAD2DEG) + match_op(OP_DEG2RAD,DEG2RAD) #undef match_op @@ -524,6 +530,21 @@ rpn_calc(rpnp_t *rpnp, rpnstack_t *rpnstack, long data_idx, stackunderflow(0); rpnstack -> s[stptr] = atan(rpnstack -> s[stptr]); break; + case OP_RAD2DEG: + stackunderflow(0); + rpnstack -> s[stptr] = 57.29577951 * rpnstack -> s[stptr]; + break; + case OP_DEG2RAD: + stackunderflow(0); + rpnstack -> s[stptr] = 0.0174532952 * rpnstack -> s[stptr]; + break; + case OP_ATAN2: + stackunderflow(1); + rpnstack -> s[stptr-1]= atan2( + rpnstack -> s[stptr-1], + rpnstack -> s[stptr]); + stptr--; + break; case OP_COS: stackunderflow(0); rpnstack -> s[stptr] = cos(rpnstack -> s[stptr]); diff --git a/src/rrd_rpncalc.h b/src/rrd_rpncalc.h index 56348db..146e2aa 100644 --- a/src/rrd_rpncalc.h +++ b/src/rrd_rpncalc.h @@ -16,7 +16,8 @@ enum op_en {OP_NUMBER=0,OP_VARIABLE,OP_INF,OP_PREV,OP_NEGINF, OP_COS,OP_LOG,OP_EXP,OP_LT,OP_LE,OP_GT,OP_GE,OP_EQ,OP_IF, 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_ATAN,OP_SQRT,OP_SORT,OP_REV,OP_TREND, + OP_ATAN2,OP_RAD2DEG,OP_DEG2RAD}; typedef struct rpnp_t { enum op_en op; -- 2.11.0