#include <assert.h> /* assertions */
#include <string.h> /* memset/memcmp */
#include <stdio.h> /* output for error messages */
-#include <values.h> /* definition of MIN_LONG, used in sc_get_val_from_long */
+#include <limits.h> /* definition of LONG_MIN, used in sc_get_val_from_long */
/*
* local definitions and macros
memset(quot, SC_0, CALC_BUFFER_SIZE);
memset(rem, SC_0, CALC_BUFFER_SIZE);
+ /* if the divisor is zero this won't work (quot is zero) */
+ if (sc_comp(divisor, quot) == 0) assert(0 && "division by zero!");
+
/* if the dividend is zero result is zero (quot is zero)*/
if (sc_comp(dividend, quot) == 0)
return;
- /* if the divisor is zero this won't work (quot is zero) */
- if (sc_comp(divisor, quot) == 0) assert(0 && "division by zero!");
if (_sign(dividend) == -1)
{
break;
}
}
- if ((carry_flag == 0) && (_val(val1[counter]) & shift != 0))
+ if ((carry_flag == 0) && (_val(val1[counter]) & shift) != 0)
carry_flag = 1;
/* shift digits to the right with offset, carry and all */
char temp1[CALC_BUFFER_SIZE];
char temp2[CALC_BUFFER_SIZE];
- const char *shl;
- char carry = SC_0;
-
- int counter, old_counter;
- int shift;
- int bitoffset;
-
offset = offset % radius;
/* rotation by multiples of the typelength is identity */
{
const char *val = (const char*)value;
int high, counter;
- char sign;
high = CALC_BUFFER_SIZE * 4;
/*
* convert to a string
+ * XXX Doesn't check buffer bounds
*/
const char *sc_print(const void *value, unsigned bits, enum base_t base)
{
char *pos;
const char *digits = small_digits;
- pos = output_buffer + BIT_PATTERN_SIZE;
- *pos = '\0';
+ pos = output_buffer + BIT_PATTERN_SIZE ;
+ *(--pos) = '\0';
/* special case */
if (bits == 0) {
CALC_BUFFER_SIZE = (4 * precision_in_bytes);
MAX_VALUE_SIZE = (2 * precision_in_bytes);
- calc_buffer = malloc(CALC_BUFFER_SIZE * sizeof(char));
- output_buffer = malloc(BIT_PATTERN_SIZE * sizeof(char));
+ calc_buffer = malloc(CALC_BUFFER_SIZE+1 * sizeof(char));
+ output_buffer = malloc(BIT_PATTERN_SIZE+1 * sizeof(char));
if (calc_buffer == NULL || output_buffer == NULL)
{