/*
- * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
if (result == NULL) result = calc_buffer;
temp = alloca(value_size);
+ /* CLEAR the buffer */
+ memset(result, 0, fc_get_buffer_length());
+
result->desc.exponent_size = exp_size;
result->desc.mantissa_size = mant_size;
fp_value *fc_rnd(const fp_value *a, fp_value *result) {
if (result == NULL) result = calc_buffer;
+ (void) a;
TRACEPRINTF(("%s ", fc_print(a, buffer, sizeof(buffer), FC_PACKED)));
TRACEPRINTF(("rounded to integer "));
}
assert(exp_val >= 0 && "floating point value not integral before fc_flt2int() call");
- shift = a->desc.mantissa_size - exp_val + 2;
+ shift = exp_val - a->desc.mantissa_size - 2;
- sc_shrI(_mant(a), shift, 64, 0, result);
+ if (shift > 0) {
+ sc_shlI(_mant(a), shift, 64, 0, result);
+ } else {
+ sc_shrI(_mant(a), -shift, 64, 0, result);
+ }
/* check for overflow */
highest = sc_get_highest_set_bit(result);
if (mode_is_signed(dst_mode)) {
if (highest == sc_get_lowest_set_bit(result)) {
/* need extra test for MIN_INT */
- if (highest >= get_mode_size_bits(dst_mode)) {
+ if (highest >= (int) get_mode_size_bits(dst_mode)) {
/* FIXME: handle overflow */
return 0;
}
} else {
- if (highest >= get_mode_size_bits(dst_mode) - 1) {
+ if (highest >= (int) get_mode_size_bits(dst_mode) - 1) {
/* FIXME: handle overflow */
return 0;
}
}
} else {
- if (highest >= get_mode_size_bits(dst_mode)) {
+ if (highest >= (int) get_mode_size_bits(dst_mode)) {
/* FIXME: handle overflow */
return 0;
}