4 * strcalc -- calculations using strings
5 * Provides basic mathematical operations on values represented as strings
11 * The module uses a string to represent values, and provides operations
12 * to perform calculations with these values.
13 * Results are stored in an internal buffer, so you have to make a copy
14 * of them if you need to store the result.
21 #define BIGGEST_INTEGER_SIZE_IN_BYTES 8
24 /*****************************************************************************
25 * typedefs, enums and structs
26 *****************************************************************************/
70 /*****************************************************************************
71 * definitions and macros
72 *****************************************************************************/
73 #define sc_add(a, b) sc_calc((a), (b), SC_ADD)
74 #define sc_sub(a, b) sc_calc((a), (b), SC_SUB)
75 #define sc_neg(a) sc_calc((a), NULL, SC_NEG)
76 #define sc_and(a, b) sc_calc((a), (b), SC_AND)
77 #define sc_or(a, b) sc_calc((a), (b), SC_OR)
78 #define sc_xor(a, b) sc_calc((a), (b), SC_XOR)
79 #define sc_not(a) sc_calc((a), NULL, SC_NOT)
80 #define sc_mul(a, b) sc_calc((a), (b), SC_MUL)
81 #define sc_div(a, b) sc_calc((a), (b), SC_DIV)
82 #define sc_mod(a, b) sc_calc((a), (b), SC_MOD)
83 #define sc_shl(a, b, c, d) sc_bitcalc((a), (b), (c), (d), SC_SHL)
84 #define sc_shr(a, b, c, d) sc_bitcalc((a), (b), (c), (d), SC_SHR)
85 #define sc_shrs(a, b, c, d) sc_bitcalc((a), (b), (c), (d), SC_SHRS)
86 #define sc_rot(a, b, c, d) sc_bitcalc((a), (b), (c), (d), SC_ROT)
88 #define sc_print_hex(a) sc_print((a), SC_HEX)
89 #define sc_print_dec(a) sc_print((a), SC_DEC)
90 #define sc_print_okt(a) sc_print((a), SC_OKT)
91 #define sc_print_bin(a) sc_print((a), SC_BIN)
92 /*****************************************************************************
93 * function declarations
94 *****************************************************************************/
95 const void *sc_get_buffer(void);
96 const int sc_get_buffer_length(void);
98 void sc_val_from_str(const char *str, unsigned int len);
99 void sc_val_from_long(long l);
100 long sc_val_to_long(const void *val);
101 void sc_min_from_bits(unsigned int num_bits, unsigned int sign);
102 void sc_max_from_bits(unsigned int num_bits, unsigned int sign);
104 void sc_calc(const void *val1, const void *val2, unsigned op);
105 void sc_bitcalc(const void *val1, const void *val2, unsigned radius, unsigned sign, unsigned op);
106 int sc_comp(const void *val1, const void *val2);
108 char* sc_print(const void *val1, unsigned base);
110 #endif /* _STRCALC_H_ */