@cryptotaxi247 / netdata-1 / commits / 44955f720

fix incorrect use of isnormal() (#5677)

Costa Tsaousis committed Mar 21, 2019 at 19:14 UTC 44955f720e1e70c9e1921616e29f6ae09de95f2c
7 files changed +19 -21
libnetdata/statistical/statistical.c
+8 -8
@@ -23,7 +23,7 @@ inline LONG_DOUBLE sum_and_count(const LONG_DOUBLE *series, size_t entries, size
23 size_t c = 0;
24
25 for(value = series; value < end ; value++) {
26 - if(isnormal(*value)) {
26 + if(calculated_number_isnumber(*value)) {
27 sum += *value;
28 c++;
29 }
@@ -62,7 +62,7 @@ LONG_DOUBLE moving_average(const LONG_DOUBLE *series, size_t entries, size_t per
62
63 for(i = 0, count = 0; i < entries; i++) {
64 LONG_DOUBLE value = series[i];
65 - if(unlikely(!isnormal(value))) continue;
65 + if(unlikely(!calculated_number_isnumber(value))) continue;
66
67 if(unlikely(count < period)) {
68 sum += value;
@@ -173,7 +173,7 @@ LONG_DOUBLE running_median_estimate(const LONG_DOUBLE *series, size_t entries) {
173
174 for(i = 0; i < entries ; i++) {
175 LONG_DOUBLE value = series[i];
176 - if(unlikely(!isnormal(value))) continue;
176 + if(unlikely(!calculated_number_isnumber(value))) continue;
177
178 average += ( value - average ) * 0.1f; // rough running average.
179 median += copysignl( average * 0.01, value - median );
@@ -193,7 +193,7 @@ LONG_DOUBLE standard_deviation(const LONG_DOUBLE *series, size_t entries) {
193 LONG_DOUBLE sum;
194
195 for(count = 0, sum = 0, value = series ; value < end ;value++) {
196 - if(likely(isnormal(*value))) {
196 + if(likely(calculated_number_isnumber(*value))) {
197 count++;
198 sum += *value;
199 }
@@ -205,7 +205,7 @@ LONG_DOUBLE standard_deviation(const LONG_DOUBLE *series, size_t entries) {
205 LONG_DOUBLE average = sum / (LONG_DOUBLE)count;
206
207 for(count = 0, sum = 0, value = series ; value < end ;value++) {
208 - if(isnormal(*value)) {
208 + if(calculated_number_isnumber(*value)) {
209 count++;
210 sum += powl(*value - average, 2);
211 }
@@ -232,7 +232,7 @@ LONG_DOUBLE single_exponential_smoothing(const LONG_DOUBLE *series, size_t entri
232 LONG_DOUBLE level = (1.0 - alpha) * (*value);
233
234 for(value++ ; value < end; value++) {
235 - if(likely(isnormal(*value)))
235 + if(likely(calculated_number_isnumber(*value)))
236 level = alpha * (*value) + (1.0 - alpha) * level;
237 }
238
@@ -250,7 +250,7 @@ LONG_DOUBLE single_exponential_smoothing_reverse(const LONG_DOUBLE *series, size
250 LONG_DOUBLE level = (1.0 - alpha) * (*value);
251
252 for(value++ ; value >= series; value--) {
253 - if(likely(isnormal(*value)))
253 + if(likely(calculated_number_isnumber(*value)))
254 level = alpha * (*value) + (1.0 - alpha) * level;
255 }
256
@@ -281,7 +281,7 @@ LONG_DOUBLE double_exponential_smoothing(const LONG_DOUBLE *series, size_t entri
281
282 const LONG_DOUBLE *value = series;
283 for(value++ ; value >= series; value--) {
284 - if(likely(isnormal(*value))) {
284 + if(likely(calculated_number_isnumber(*value))) {
285
286 LONG_DOUBLE last_level = level;
287 level = alpha * *value + (1.0 - alpha) * (level + trend);
libnetdata/statistical/statistical.h
-4
@@ -5,10 +5,6 @@
5
6 #include "../libnetdata.h"
7
8 -#ifndef isnormal
9 -#define isnormal(x) (fpclassify(x) == FP_NORMAL)
10 -#endif
11 -
8 extern void log_series_to_stderr(LONG_DOUBLE *series, size_t entries, calculated_number result, const char *msg);
9
10 extern LONG_DOUBLE average(const LONG_DOUBLE *series, size_t entries);
libnetdata/storage_number/storage_number.h
+2
@@ -55,6 +55,8 @@ typedef long double collected_number;
55
56 #define calculated_number_equal(a, b) (calculated_number_fabs((a) - (b)) < calculated_number_epsilon)
57
58 +#define calculated_number_isnumber(a) (!(fpclassify(a) & (FP_NAN|FP_INFINITE)))
59 +
60 typedef uint32_t storage_number;
61 #define STORAGE_NUMBER_FORMAT "%u"
62
web/api/queries/des/des.c
+2 -2
@@ -99,7 +99,7 @@ void grouping_free_des(RRDR *r) {
99 void grouping_add_des(RRDR *r, calculated_number value) {
100 struct grouping_des *g = (struct grouping_des *)r->internal.grouping_data;
101
102 - if(isnormal(value)) {
102 + if(calculated_number_isnumber(value)) {
103 if(likely(g->count > 0)) {
104 // we have at least a number so far
105
@@ -128,7 +128,7 @@ void grouping_add_des(RRDR *r, calculated_number value) {
128 calculated_number grouping_flush_des(RRDR *r, RRDR_VALUE_FLAGS *rrdr_value_options_ptr) {
129 struct grouping_des *g = (struct grouping_des *)r->internal.grouping_data;
130
131 - if(unlikely(!g->count || !isnormal(g->level))) {
131 + if(unlikely(!g->count || !calculated_number_isnumber(g->level))) {
132 *rrdr_value_options_ptr |= RRDR_VALUE_EMPTY;
133 return 0.0;
134 }
web/api/queries/median/median.c
+2 -2
@@ -42,7 +42,7 @@ void grouping_add_median(RRDR *r, calculated_number value) {
42 error("INTERNAL ERROR: median buffer overflow on chart '%s' - next_pos = %zu, series_size = %zu, r->group = %ld.", r->st->name, g->next_pos, g->series_size, r->group);
43 }
44 else {
45 - if(isnormal(value))
45 + if(calculated_number_isnumber(value))
46 g->series[g->next_pos++] = (LONG_DOUBLE)value;
47 }
48 }
@@ -64,7 +64,7 @@ calculated_number grouping_flush_median(RRDR *r, RRDR_VALUE_FLAGS *rrdr_value_op
64 else
65 value = (calculated_number)g->series[0];
66
67 - if(!isnormal(value)) {
67 + if(!calculated_number_isnumber(value)) {
68 value = 0.0;
69 *rrdr_value_options_ptr |= RRDR_VALUE_EMPTY;
70 }
web/api/queries/ses/ses.c
+2 -2
@@ -71,7 +71,7 @@ void grouping_free_ses(RRDR *r) {
71 void grouping_add_ses(RRDR *r, calculated_number value) {
72 struct grouping_ses *g = (struct grouping_ses *)r->internal.grouping_data;
73
74 - if(isnormal(value)) {
74 + if(calculated_number_isnumber(value)) {
75 if(unlikely(!g->count))
76 g->level = value;
77
@@ -83,7 +83,7 @@ void grouping_add_ses(RRDR *r, calculated_number value) {
83 calculated_number grouping_flush_ses(RRDR *r, RRDR_VALUE_FLAGS *rrdr_value_options_ptr) {
84 struct grouping_ses *g = (struct grouping_ses *)r->internal.grouping_data;
85
86 - if(unlikely(!g->count || !isnormal(g->level))) {
86 + if(unlikely(!g->count || !calculated_number_isnumber(g->level))) {
87 *rrdr_value_options_ptr |= RRDR_VALUE_EMPTY;
88 return 0.0;
89 }
web/api/queries/stddev/stddev.c
+3 -3
@@ -36,7 +36,7 @@ void grouping_free_stddev(RRDR *r) {
36 void grouping_add_stddev(RRDR *r, calculated_number value) {
37 struct grouping_stddev *g = (struct grouping_stddev *)r->internal.grouping_data;
38
39 - if(isnormal(value)) {
39 + if(calculated_number_isnumber(value)) {
40 g->count++;
41
42 // See Knuth TAOCP vol 2, 3rd edition, page 232
@@ -74,7 +74,7 @@ calculated_number grouping_flush_stddev(RRDR *r, RRDR_VALUE_FLAGS *rrdr_value_op
74 if(likely(g->count > 1)) {
75 value = stddev(g);
76
77 - if(!isnormal(value)) {
77 + if(!calculated_number_isnumber(value)) {
78 value = 0.0;
79 *rrdr_value_options_ptr |= RRDR_VALUE_EMPTY;
80 }
@@ -102,7 +102,7 @@ calculated_number grouping_flush_coefficient_of_variation(RRDR *r, RRDR_VALUE_FL
102 calculated_number m = mean(g);
103 value = 100.0 * stddev(g) / ((m < 0)? -m : m);
104
105 - if(unlikely(!isnormal(value))) {
105 + if(unlikely(!calculated_number_isnumber(value))) {
106 value = 0.0;
107 *rrdr_value_options_ptr |= RRDR_VALUE_EMPTY;
108 }