]> arthur.barton.de Git - netdata.git/blob - src/storage_number.h
e26fde78767f14fe7278275415dd9c52d6907309
[netdata.git] / src / storage_number.h
1 #include <inttypes.h>
2
3 #ifndef NETDATA_STORAGE_NUMBER_H
4 #define NETDATA_STORAGE_NUMBER_H
5
6 typedef long double calculated_number;
7 #define CALCULATED_NUMBER_FORMAT "%0.7Lf"
8 //typedef long long calculated_number;
9 //#define CALCULATED_NUMBER_FORMAT "%lld"
10
11 typedef long long collected_number;
12 #define COLLECTED_NUMBER_FORMAT "%lld"
13
14 typedef int32_t storage_number;
15 typedef uint32_t ustorage_number;
16 #define STORAGE_NUMBER_FORMAT "%d"
17
18 #define SN_NOT_EXISTS           (0x0 << 24)
19 #define SN_EXISTS                       (0x1 << 24)
20 #define SN_EXISTS_RESET         (0x2 << 24)
21 #define SN_EXISTS_UNDEF1        (0x3 << 24)
22 #define SN_EXISTS_UNDEF2        (0x4 << 24)
23 #define SN_EXISTS_UNDEF3        (0x5 << 24)
24 #define SN_EXISTS_UNDEF4        (0x6 << 24)
25
26 #define SN_FLAGS_MASK           (~(0x6 << 24))
27
28 // extract the flags
29 #define get_storage_number_flags(value) ((((storage_number)value) & (1 << 24)) | (((storage_number)value) & (2 << 24)) | (((storage_number)value) & (4 << 24)))
30
31 // checks
32 #define does_storage_number_exist(value) ((get_storage_number_flags(value) != 0)?1:0)
33 #define did_storage_number_reset(value)  ((get_storage_number_flags(value) == SN_EXISTS_RESET)?1:0)
34
35 storage_number pack_storage_number(calculated_number value, uint32_t flags);
36 calculated_number unpack_storage_number(storage_number value);
37
38 int print_calculated_number(char *str, calculated_number value);
39
40 #define STORAGE_NUMBER_POSITIVE_MAX 167772150000000.0
41 #define STORAGE_NUMBER_POSITIVE_MIN 0.00001
42 #define STORAGE_NUMBER_NEGATIVE_MAX -0.00001
43 #define STORAGE_NUMBER_NEGATIVE_MIN -167772150000000.0
44
45 // accepted accuracy loss
46 #define ACCURACY_LOSS 0.0001
47 #define accuracy_loss(t1, t2) ((t1 == t2 || t1 == 0.0 || t2 == 0.0) ? 0.0 : (100.0 - ((t1 > t2) ? (t2 * 100.0 / t1 ) : (t1 * 100.0 / t2))))
48
49 #endif /* NETDATA_STORAGE_NUMBER_H */