diff --git a/src/pmwebapi/pmgraphite.cxx b/src/pmwebapi/pmgraphite.cxx index 86a52b7..57b05e1 100644 --- a/src/pmwebapi/pmgraphite.cxx +++ b/src/pmwebapi/pmgraphite.cxx @@ -1,7 +1,7 @@ /* * PMWEBD graphite-api emulation * - * Copyright (c) 2014 Red Hat Inc. + * Copyright (c) 2014-2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -33,7 +33,6 @@ using namespace std; extern "C" { #include -#include #ifdef HAVE_FTS_H #include #endif @@ -42,6 +41,12 @@ extern "C" #ifdef HAVE_PTHREAD_H #include #endif +#ifdef HAVE_IEEEFP_H +#include +#endif +#ifdef HAVE_MATH_H +#include +#endif #ifdef HAVE_CAIRO #include #endif @@ -49,6 +54,43 @@ extern "C" /* + * Platform-independent not-a-number helpers (based on libpcp code). + */ +static int +pmgraphite_isnanf (float value) +{ + int fp_bad = 0; + +#ifdef HAVE_FPCLASSIFY + fp_bad = fpclassify (value) == FP_NAN; +#else +#ifdef HAVE_ISNANF + fp_bad = isnanf (value); +#else +# warning "This platform has no isnan for float" +#endif +#endif + return fp_bad; +} + +static int +pmgraphite_isnand (double value) +{ + int fp_bad = 0; + +#ifdef HAVE_FPCLASSIFY + fp_bad = fpclassify (value) == FP_NAN; +#else +#ifdef HAVE_ISNAN + fp_bad = isnan (value); +#else +# warning "This platform has no isnan for double" +#endif +#endif + return fp_bad; +} + +/* * We need a reversible encoding from arbitrary non-empty strings * (such as archive path names, pcp metric name components (?), pcp * instance names) to the dot-separated components of graphite metric @@ -966,7 +1008,7 @@ void pmgraphite_fetch_series (fetch_series_jobspec *spec) delta = 1; // some token protection against div-by-zero } - if (isnanf (last_value) || isnanf (this_value)) { + if (pmgraphite_isnanf (last_value) || pmgraphite_isnanf (this_value)) { output[i].what = nanf (""); } else { // avoid loss of significance risk of naively calculating @@ -1698,10 +1740,10 @@ pmgraphite_respond_render_gfx (struct MHD_Connection *connection, ymin = nanf (""); for (unsigned i=0; i& f = all_results[i]; for (unsigned j=0; j