]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
merged changes
authorJulien Thomas <jthomas@exosec.fr>
Fri, 7 Feb 2014 13:21:53 +0000 (14:21 +0100)
committerTobias Oetiker <tobi@oetiker.ch>
Fri, 14 Feb 2014 12:53:19 +0000 (13:53 +0100)
doc/rrdgraph_rpn.pod
src/rrd_rpncalc.c
src/rrd_rpncalc.h

index 87fc8e666132a57524885f6f8e7ac7a49302078f..733cfaa422e0b04dfcaf626bf21e610e778d77b7 100644 (file)
@@ -79,6 +79,12 @@ respectively.  Note that I<infinite> is larger than anything else.
 If one of the input numbers is I<unknown> then the result of the operation will be
 I<unknown> too.
 
+B<MINNAN, MAXNAN>
+
+NAN-safe version of MIN and MAX. If one of the input numbers is I<unknown>
+then the result of the operation will be the other one. If both are
+I<unknown>, then the result of the operation is I<unknown>.
+
 B<LIMIT>
 
 Pops two elements from the stack and uses them to define a range.
index 2587e4448145a6d1d51f5dc6d3fd0758560c95dd..3ac63872589eb0a3c18beea92e6e441fd694c625 100644 (file)
@@ -185,6 +185,8 @@ void rpn_compact2str(
             add_op(OP_AVG, AVG)
             add_op(OP_ABS, ABS)
             add_op(OP_ADDNAN, ADDNAN)
+            add_op(OP_MINNAN, MINNAN)
+            add_op(OP_MAXNAN, MAXNAN)
 #undef add_op
     }
     (*str)[offset] = '\0';
@@ -388,7 +390,10 @@ rpnp_t   *rpn_parse(
             match_op(OP_AVG, AVG)
             match_op(OP_ABS, ABS)
             match_op(OP_ADDNAN, ADDNAN)
+            match_op(OP_MINNAN, MINNAN)
+            match_op(OP_MAXNAN, MAXNAN)
             match_op(OP_MEDIAN, MEDIAN)
+
 #undef match_op
             else if ((sscanf(expr, DEF_NAM_FMT "%n", vname, &pos) == 1)
                      && ((rpnp[steps].ptr = (*lookup) (key_hash, vname)) !=
@@ -736,6 +741,15 @@ short rpn_calc(
                 rpnstack->s[stptr - 1] = rpnstack->s[stptr];
             stptr--;
             break;
+        case OP_MINNAN:
+            stackunderflow(1);
+            if (isnan(rpnstack->s[stptr - 1]))
+                rpnstack->s[stptr - 1] = rpnstack->s[stptr];
+            else if (isnan(rpnstack->s[stptr]));
+            else if (rpnstack->s[stptr - 1] > rpnstack->s[stptr])
+                rpnstack->s[stptr - 1] = rpnstack->s[stptr];
+            stptr--;
+            break;
         case OP_MAX:
             stackunderflow(1);
             if (isnan(rpnstack->s[stptr - 1]));
@@ -745,6 +759,15 @@ short rpn_calc(
                 rpnstack->s[stptr - 1] = rpnstack->s[stptr];
             stptr--;
             break;
+        case OP_MAXNAN:
+            stackunderflow(1);
+            if (isnan(rpnstack->s[stptr - 1]))
+                rpnstack->s[stptr - 1] = rpnstack->s[stptr];
+            else if (isnan(rpnstack->s[stptr]));
+            else if (rpnstack->s[stptr - 1] < rpnstack->s[stptr])
+                rpnstack->s[stptr - 1] = rpnstack->s[stptr];
+            stptr--;
+            break;
         case OP_LIMIT:
             stackunderflow(2);
             if (isnan(rpnstack->s[stptr - 2]));
index 9661e6a01e10b3125235e680012c6aff7ac4f143..dd9f109e27b4548dbcb95ea4e1437ed44bb54314 100644 (file)
@@ -19,8 +19,10 @@ enum op_en { OP_NUMBER = 0, OP_VARIABLE, OP_INF, OP_PREV, OP_NEGINF,
     OP_ATAN, OP_SQRT, OP_SORT, OP_REV, OP_TREND, OP_TRENDNAN,
     OP_ATAN2, OP_RAD2DEG, OP_DEG2RAD,
     OP_PREDICT,OP_PREDICTSIGMA,
-    OP_AVG, OP_ABS, OP_ADDNAN, OP_MEDIAN
-};
+    OP_AVG, OP_ABS, OP_ADDNAN,
+    OP_MINNAN, OP_MAXNAN,
+    OP_MEDIAN
+ };
 
 typedef struct rpnp_t {
     enum op_en op;