-
Notifications
You must be signed in to change notification settings - Fork 4
/
num.h
63 lines (51 loc) · 1.21 KB
/
num.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef UNIT_H
#define UNIT_H
#include <stdint.h>
// multiples of msat
#define MSATOSHI 1LL
#define SATOSHI 1000LL
#define FINNEY 10000LL
#define BITS 100000LL
#define MBTC 100000000LL
#define BTC 100000000000LL
enum unit {
UNIT_BTC,
UNIT_MBTC,
UNIT_BITS,
UNIT_FINNEY,
UNIT_SATOSHI,
UNIT_MSATOSHI,
UNIT_OTHER,
UNIT_NONE,
};
enum num_type {
TYPE_INT,
TYPE_FLOAT
};
struct lexunit {
char *name;
enum unit unit;
};
struct num
{
enum num_type type;
enum unit unit;
const char *unitstr;
union {
int64_t intval;
double floatval;
};
};
extern struct num g_other;
extern char *g_other_name;
void num_add(struct num *dst, struct num *a, struct num *b);
void num_sub(struct num *dst, struct num *a, struct num *b);
void num_mul(struct num *dst, struct num *a, struct num *b);
void num_div(struct num *dst, struct num *a, struct num *b);
void num_assign(struct num *dst, struct num *a);
void num_init(struct num *num);
void num_print(struct num *num, enum unit unit, char *unitname, int print_unit);
void num_init_float(struct num *num, double val, enum unit unit);
void num_init_int(struct num *num, int64_t val, enum unit unit);
char *unit_name(enum unit unit);
#endif /* UNIT_H */