#include <assert.h> /* assertions */
#include <string.h> /* memset/memcmp */
#include <stdio.h> /* output for error messages */
#include <assert.h> /* assertions */
#include <string.h> /* memset/memcmp */
#include <stdio.h> /* output for error messages */
- char temp_buffer[CALC_BUFFER_SIZE]; /* result buffer */
- char neg_val1[CALC_BUFFER_SIZE]; /* abs of val1 */
- char neg_val2[CALC_BUFFER_SIZE]; /* abs of val2 */
+ char* temp_buffer; /* result buffer */
+ char* neg_val1; /* abs of val1 */
+ char* neg_val2; /* abs of val2 */
const char *mul, *add1, *add2; /* intermediate result containers */
char carry = SC_0; /* container for carries */
char sign = 0; /* marks result sign */
int c_inner, c_outer; /* loop counters */
const char *mul, *add1, *add2; /* intermediate result containers */
char carry = SC_0; /* container for carries */
char sign = 0; /* marks result sign */
int c_inner, c_outer; /* loop counters */
/* init result buffer to zeroes */
memset(temp_buffer, SC_0, CALC_BUFFER_SIZE);
/* init result buffer to zeroes */
memset(temp_buffer, SC_0, CALC_BUFFER_SIZE);
_negate(val2, temp_buffer);
_add(val1, temp_buffer, buffer);
_negate(val2, temp_buffer);
_add(val1, temp_buffer, buffer);
static void _divmod(const char *dividend, const char *divisor, char *quot, char *rem)
{
const char *minus_divisor;
static void _divmod(const char *dividend, const char *divisor, char *quot, char *rem)
{
const char *minus_divisor;
/* clear result buffer */
memset(quot, SC_0, CALC_BUFFER_SIZE);
memset(rem, SC_0, CALC_BUFFER_SIZE);
/* clear result buffer */
memset(quot, SC_0, CALC_BUFFER_SIZE);
memset(rem, SC_0, CALC_BUFFER_SIZE);
/* positive: low-order -> high order, negative other direction */
static void _rot(const char *val1, char *buffer, long offset, int radius, unsigned is_signed)
{
/* positive: low-order -> high order, negative other direction */
static void _rot(const char *val1, char *buffer, long offset, int radius, unsigned is_signed)
{
void sc_calc(const void* value1, const void* value2, unsigned op, void *buffer)
{
void sc_calc(const void* value1, const void* value2, unsigned op, void *buffer)
{
case SC_NEG:
_negate(val1, calc_buffer);
DEBUGPRINTF_COMPUTATION(("negated: %s\n", sc_print_hex(calc_buffer)));
case SC_NEG:
_negate(val1, calc_buffer);
DEBUGPRINTF_COMPUTATION(("negated: %s\n", sc_print_hex(calc_buffer)));
case SC_OR:
DEBUGPRINTF_COMPUTATION(("| "));
_bitor(val1, val2, calc_buffer);
case SC_OR:
DEBUGPRINTF_COMPUTATION(("| "));
_bitor(val1, val2, calc_buffer);
case SC_NOT:
_bitnot(val1, calc_buffer);
DEBUGPRINTF_COMPUTATION(("bit-negated: %s\n", sc_print_hex(calc_buffer)));
case SC_NOT:
_bitnot(val1, calc_buffer);
DEBUGPRINTF_COMPUTATION(("bit-negated: %s\n", sc_print_hex(calc_buffer)));
case SC_ADD:
DEBUGPRINTF_COMPUTATION(("+ "));
_add(val1, val2, calc_buffer);
case SC_ADD:
DEBUGPRINTF_COMPUTATION(("+ "));
_add(val1, val2, calc_buffer);
static const char big_digits[] = "0123456789ABCDEF";
static const char small_digits[] = "0123456789abcdef";
static const char big_digits[] = "0123456789ABCDEF";
static const char small_digits[] = "0123456789abcdef";
- char base_val[CALC_BUFFER_SIZE];
- char div1_res[CALC_BUFFER_SIZE];
- char div2_res[CALC_BUFFER_SIZE];
- char rem_res[CALC_BUFFER_SIZE];
+ char *base_val, *div1_res, *div2_res, *rem_res;
int counter, nibbles, i, sign;
char x;
int counter, nibbles, i, sign;
char x;
BIT_PATTERN_SIZE = (precision);
CALC_BUFFER_SIZE = (precision / 2);
MAX_VALUE_SIZE = (precision / 4);
BIT_PATTERN_SIZE = (precision);
CALC_BUFFER_SIZE = (precision / 2);
MAX_VALUE_SIZE = (precision / 4);
DEBUGPRINTF(("init strcalc: \n\tPRECISION: %d\n\tCALC_BUFFER_SIZE = %d\n\tMAX_VALUE_SIZE = %d\n\tbuffer pointer: %p\n", precision, CALC_BUFFER_SIZE, MAX_VALUE_SIZE, calc_buffer));
}
}
DEBUGPRINTF(("init strcalc: \n\tPRECISION: %d\n\tCALC_BUFFER_SIZE = %d\n\tMAX_VALUE_SIZE = %d\n\tbuffer pointer: %p\n", precision, CALC_BUFFER_SIZE, MAX_VALUE_SIZE, calc_buffer));
}
}