[rrd-users] CDEF,RPN, no decimal constant possible?

Peter pspiegler at gmx.de
Fri Jul 11 10:02:49 CEST 2014


the problem is in void parseCDEF_DS(const char *def,rrd_t *rrd,int ds_idx) in
rrd_rpncalc.c:
1. Parse the def "DeLog_L,LOG,4.34294481903252,*"
  rpnp = rpn_parse((void *) rrd, def, &lookup_DS);

rpnp is array of 
typedef struct rpnp_t {
    enum op_en op;
    double    val;      /* value for a OP_NUMBER */
    long      ptr;      /* pointer into the gdes array for OP_VAR */
    double   *data;     /* pointer to the current value from OP_VAR DAS */
    long      ds_cnt;   /* data source count for data pointer */
    long      step;     /* time step for OP_VAR das */
} rpnp_t;
and store the val: 4.34294481903252

But later is called 

   if (rpn_compact(rpnp, &rpnc, &count) == -1) {

and rpnc is array of 
/* a compact representation of rpnp_t for computed data sources */
typedef struct rpn_cdefds_t {
    char      op;       /* rpn operator type */
    short     val;      /* used by OP_NUMBER and OP_VARIABLE */
} rpn_cdefds_t;

Now val is only a short int.
In rpn_compact(    rpnp_t *rpnp,    rpn_cdefds_t **rpnc,    short *count)
the double to short conversion occures at line:
       if (rpnp[i].op == OP_NUMBER) {
            /* rpnp.val is a double, rpnc.val is a short */
            double    temp = floor(rpnp[i].val);
          if (temp < SHRT_MIN || temp > SHRT_MAX) {
                rrd_set_error ("constants must be integers in the interval
(%d, %d)", SHRT_MIN, SHRT_MAX);
                free(*rpnc);  return -1; }

Because later in parseCDEF_DS the rpnc  array is stored by memcpy:
   /* copy the compact rpn representation over the ds_def par array */
    memcpy((void *) &(rrd->ds_def[ds_idx].par[DS_cdef]),(void *) rpnc, count
* sizeof(rpn_cdefds_t));
and possible so stored in the rrd file it would not binary compatible to
change val to double in typedef struct rpn_cdefds_t. 

Conclusion:
Numbers in a rpn expression are coerced to a short integer without error.
Only values otside of the short range  [-32768,32767] are indicated by an
error.

This should be documented, i.e. in
http://oss.oetiker.ch/rrdtool/doc/rrdgraph_rpn.en.html 

To save some bytes the very good rpn calculator is crippled.
Possible that can changed in a future release.

Peter






--
View this message in context: http://rrd-mailinglists.937164.n2.nabble.com/CDEF-RPN-no-decimal-constant-possible-tp7582283p7582297.html
Sent from the RRDtool Users Mailinglist mailing list archive at Nabble.com.



More information about the rrd-users mailing list