]> arthur.barton.de Git - netdata.git/blob - src/storage_number.h
Command line: Follow IEEE Std 1003.1, 2013 Edition
[netdata.git] / src / storage_number.h
1 #include <stdint.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 /*
15 typedef long double collected_number;
16 #define COLLECTED_NUMBER_FORMAT "%0.7Lf"
17 */
18
19 typedef int32_t storage_number;
20 typedef uint32_t ustorage_number;
21 #define STORAGE_NUMBER_FORMAT "%d"
22
23 #define SN_NOT_EXISTS           (0x0 << 24)
24 #define SN_EXISTS                       (0x1 << 24)
25 #define SN_EXISTS_RESET         (0x2 << 24)
26 #define SN_EXISTS_UNDEF1        (0x3 << 24)
27 #define SN_EXISTS_UNDEF2        (0x4 << 24)
28 #define SN_EXISTS_UNDEF3        (0x5 << 24)
29 #define SN_EXISTS_UNDEF4        (0x6 << 24)
30
31 #define SN_FLAGS_MASK           (~(0x6 << 24))
32
33 // extract the flags
34 #define get_storage_number_flags(value) ((((storage_number)value) & (1 << 24)) | (((storage_number)value) & (2 << 24)) | (((storage_number)value) & (4 << 24)))
35
36 // checks
37 #define does_storage_number_exist(value) ((get_storage_number_flags(value) != 0)?1:0)
38 #define did_storage_number_reset(value)  ((get_storage_number_flags(value) == SN_EXISTS_RESET)?1:0)
39
40 storage_number pack_storage_number(calculated_number value, uint32_t flags);
41 calculated_number unpack_storage_number(storage_number value);
42
43 int print_calculated_number(char *str, calculated_number value);
44
45 #define STORAGE_NUMBER_POSITIVE_MAX 167772150000000.0
46 #define STORAGE_NUMBER_POSITIVE_MIN 0.00001
47 #define STORAGE_NUMBER_NEGATIVE_MAX -0.00001
48 #define STORAGE_NUMBER_NEGATIVE_MIN -167772150000000.0
49
50 // accepted accuracy loss
51 #define ACCURACY_LOSS 0.0001
52 #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))))
53
54 #endif /* NETDATA_STORAGE_NUMBER_H */