1 #ifndef NETDATA_STORAGE_NUMBER_H
2 #define NETDATA_STORAGE_NUMBER_H
4 typedef long double calculated_number;
5 #define CALCULATED_NUMBER_FORMAT "%0.7Lf"
6 //typedef long long calculated_number;
7 //#define CALCULATED_NUMBER_FORMAT "%lld"
9 typedef long long collected_number;
10 #define COLLECTED_NUMBER_FORMAT "%lld"
12 typedef int32_t storage_number;
13 typedef uint32_t ustorage_number;
14 #define STORAGE_NUMBER_FORMAT "%d"
16 #define SN_NOT_EXISTS (0x0 << 24)
17 #define SN_EXISTS (0x1 << 24)
18 #define SN_EXISTS_RESET (0x2 << 24)
19 #define SN_EXISTS_UNDEF1 (0x3 << 24)
20 #define SN_EXISTS_UNDEF2 (0x4 << 24)
21 #define SN_EXISTS_UNDEF3 (0x5 << 24)
22 #define SN_EXISTS_UNDEF4 (0x6 << 24)
24 #define SN_FLAGS_MASK (~(0x6 << 24))
27 #define get_storage_number_flags(value) ((((storage_number)value) & (1 << 24)) | (((storage_number)value) & (2 << 24)) | (((storage_number)value) & (4 << 24)))
30 #define does_storage_number_exist(value) ((get_storage_number_flags(value) != 0)?1:0)
31 #define did_storage_number_reset(value) ((get_storage_number_flags(value) == SN_EXISTS_RESET)?1:0)
33 storage_number pack_storage_number(calculated_number value, uint32_t flags);
34 calculated_number unpack_storage_number(storage_number value);
36 int print_calculated_number(char *str, calculated_number value);
38 #define STORAGE_NUMBER_POSITIVE_MAX 167772150000000.0
39 #define STORAGE_NUMBER_POSITIVE_MIN 0.00001
40 #define STORAGE_NUMBER_NEGATIVE_MAX -0.00001
41 #define STORAGE_NUMBER_NEGATIVE_MIN -167772150000000.0
43 // accepted accuracy loss
44 #define ACCURACY_LOSS 0.0001
45 #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))))
47 #endif /* NETDATA_STORAGE_NUMBER_H */