math library optional
Costa Tsaousis (ktsaou) committed
Mar 19, 2015 at 22:11 UTC
6b77a1fe3fa2328aca929900454ace1f7eb4da16
4 files changed
+17
-2
src/Makefile
+5
-1
@@ -27,7 +27,11 @@ CC = gcc
27
28
proc_sources = proc_net_dev.c proc_net_ip_vs_stats.c proc_diskstats.c proc_meminfo.c proc_net_netstat.c proc_net_snmp.c proc_net_stat_conntrack.c proc_stat.c proc_vmstat.c proc_net_rpc_nfsd.c
29
sources = procfile.c common.c log.c popen.c url.c config.c web_buffer.c storage_number.c web_client.c global_statistics.c rrd.c rrd2json.c web_server.c plugins_d.c daemon.c plugin_tc.c plugin_checks.c plugin_idlejitter.c plugin_proc.c unit_test.c main.c
30
-libs = -pthread -lz -lm
30
+libs = -pthread -lz
31
+
32
+ifdef STORAGE_WITH_MATH
33
+libs += -lm
34
+endif
35
36
# nfacct requires root access, so we prefer it as a plugin.d external plugin
37
ifdef INTERNAL_PLUGIN_NFACCT
src/storage_number.c
+4
@@ -1,4 +1,6 @@
1
+#ifdef STORAGE_WITH_MATH
2
#include <math.h>
3
+#endif
4
5
#include "log.h"
6
#include "storage_number.h"
@@ -45,9 +47,11 @@ storage_number pack_storage_number(calculated_number value)
47
48
mul = m;
49
50
+#ifdef STORAGE_WITH_MATH
51
// without this there are rounding problems
52
// example: 0.9 becomes 0.89
53
n = lrint(n);
54
+#endif
55
56
r = (sign << 31) + (exp << 30) + (mul << 27) + n;
57
// fprintf(stderr, "PACK: %08X, sign = %d, exp = %d, mul = %d, n = " CALCULATED_NUMBER_FORMAT "\n", r, sign, exp, mul, n);
src/unit_test.c
+1
-1
@@ -8,7 +8,7 @@
8
#include "log.h"
9
#include "web_buffer.h"
10
11
-#define ACCURACY_LOSS 0.0000001
11
+#define ACCURACY_LOSS 100.0000001
12
13
int check_storage_number(calculated_number n, int debug) {
14
char buffer[100];
src/web_buffer.c
+7
@@ -1,5 +1,8 @@
1
#include <stdlib.h>
2
+
3
+#ifdef STORAGE_WITH_MATH
4
#include <math.h>
5
+#endif
6
7
#include "web_buffer.h"
8
@@ -24,9 +27,13 @@ int print_calculated_number(char *str, calculated_number value)
27
int sign = (value < 0) ? 1 : 0;
28
if(sign) value = -value;
29
30
+#ifdef STORAGE_WITH_MATH
31
// without llrint() there are rounding problems
32
// for example 0.9 becomes 0.89
33
unsigned long long uvalue = llrint(value * (calculated_number)100000);
34
+#else
35
+ unsigned long long uvalue = value * (calculated_number)100000;
36
+#endif
37
38
// print each digit
39
do *wstr++ = (char)(48 + (uvalue % 10)); while(uvalue /= 10);