When a counter is constant between two samples the delta is zero.
The previous guard `d_value > 0` treated that the same as a negative
delta (counter reset) and returned NaN instead of 0. Changing to
`d_value >= 0` preserves the counter-reset protection while correctly
returning 0.0 for a flat counter.
Reported by @bitionaire, fix by @oetiker.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
====================
Bugfixes
--------
+* libdbi /derive now returns 0 instead of NaN when the underlying
+ counter is constant (zero delta). Previously the strict `d_value > 0`
+ guard skipped zero deltas the same way it skips negative ones (counter
+ resets). Changed to `d_value >= 0`. Issue #550 reported by
+ @bitionaire, fix by @oetiker.
* Pad the Perl `$RRDs::VERSION` / `$RRDp::VERSION` numeric encoding so
two-digit minor releases compare monotonically. The numeric version
now uses three-digit zero-padded minor and patch fields, e.g.
r_value=DNAN;
/* check for timestamp delta to be within an acceptable range */
if ((d_timestamp>0)&&(d_timestamp<2*derive)) {
- /* only handle positive delta - avoid wrap-arounds/counter resets showing up as spikes */
- if (d_value>0) {
+ /* only handle non-negative delta - avoid wrap-arounds/counter resets showing up as spikes */
+ if (d_value>=0) {
/* and normalize to per second */
r_value=d_value/d_timestamp;
}