]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Adding Rounding Function
authorTheWitness <thewitness@cacti.net>
Sun, 3 Mar 2019 13:10:07 +0000 (08:10 -0500)
committerTobias Oetiker <tobi@oetiker.ch>
Wed, 5 Jun 2019 18:09:18 +0000 (20:09 +0200)
doc/rrdgraph_rpn.pod
src/rrd_rpncalc.c
src/rrd_rpncalc.h

index de769ae3c49dca94dfa2527d65df61709d790bf9..3026bed93d63aafa8ed9e8f3cc4d077d14827b5a 100644 (file)
@@ -142,6 +142,10 @@ B<FLOOR, CEIL>
 
 Round down or up to the nearest integer.
 
+B<ROUND>
+
+Round to the nearest integer.
+
 B<DEG2RAD, RAD2DEG>
 
 Convert angle in degrees to radians, or radians to degrees.
index 630651ac58d7e4b183980a189227dafddcfe97bd..0f54c6be6ba2fe073c47a7ebcf5a94a37dc35044 100644 (file)
@@ -212,6 +212,7 @@ void rpn_compact2str(
             add_op(OP_ROLL, ROLL)
             add_op(OP_INDEX, INDEX)
             add_op(OP_POW, POW)
+            add_op(OP_ROUND, ROUND)
 #undef add_op
     }
     (*str)[offset] = '\0';
@@ -445,6 +446,7 @@ rpnp_t   *rpn_parse(
             match_op(OP_STDEV, STDEV)
             match_op(OP_PERCENT, PERCENT)
             match_op(OP_POW, POW)
+            match_op(OP_ROUND, ROUND)
 
 #undef match_op
             else if ((sscanf(expr, DEF_NAM_FMT "%n", vname, &pos) == 1)
@@ -790,6 +792,10 @@ short rpn_calc(
             stackunderflow(0);
             rpnstack->s[stptr] = ceil(rpnstack->s[stptr]);
             break;
+        case OP_ROUND:
+            stackunderflow(0);
+            rpnstack->s[stptr] = round(rpnstack->s[stptr]);
+            break;
         case OP_FLOOR:
             stackunderflow(0);
             rpnstack->s[stptr] = floor(rpnstack->s[stptr]);
index 9ee921daa98593eaeaddd7316b6efddf64d76c2c..55eff62a07a1987b96187cf1db69a60be77b67e3 100644 (file)
@@ -24,7 +24,7 @@ enum op_en { OP_NUMBER = 0, OP_VARIABLE, OP_INF, OP_PREV, OP_NEGINF,
     OP_MEDIAN, OP_PREDICTPERC,
     OP_DEPTH, OP_COPY, OP_ROLL, OP_INDEX, OP_STEPWIDTH,
     OP_NEWDAY, OP_NEWWEEK, OP_NEWMONTH, OP_NEWYEAR,
-    OP_SMIN, OP_SMAX, OP_STDEV, OP_PERCENT, OP_POW
+    OP_SMIN, OP_SMAX, OP_STDEV, OP_PERCENT, OP_POW, OP_ROUND
  };
 
 typedef struct rpnp_t {