script_num.h (809B)
1 2 #ifndef BTCS_SCRIPTNUM_H 3 #define BTCS_SCRIPTNUM_H 4 5 #include "misc.h" 6 #include "val.h" 7 8 enum sn_result { 9 SN_SUCCESS, 10 SN_ERR_OVERFLOWED_INT 11 }; 12 13 struct num { 14 s64 val; 15 int ind; 16 }; 17 18 void 19 sn_from_int(s64 n, struct num *); 20 21 int 22 sn_overflowed(struct num *num); 23 24 enum sn_result 25 sn_from_val(struct val val, struct num ** sn); 26 27 struct val 28 sn_to_val(struct num *sn); 29 30 int 31 sn_to_int(struct num *sn, int require_minimal); 32 33 void 34 sn_serialize(struct num *sn, u8 *buf, int bufsize, u16 *len); 35 36 37 inline static void sn_add(struct num *a, struct num *b, struct num *c) { 38 c->val = a->val + b->val; 39 } 40 41 inline static void sn_sub(struct num *a, struct num *b, struct num *c) { 42 c->val = a->val - b->val; 43 } 44 45 inline static void sn_neg(struct num *a, struct num *b) { 46 b->val = -(a->val); 47 } 48 49 50 #endif /* BTCS_SCRIPTNUM_H */