bcalc

cli bitcoin unit calculator
git clone git://jb55.com/bcalc
Log | Files | Refs | README | LICENSE

num.h (1243B)


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