Commit 13c1bd27 authored by Michael Beck's avatar Michael Beck
Browse files

Fixed floating point minimum values, must be -*_MAX, not *_MIN !

Added floating point conversions...

[r1216]
parent dc467413
......@@ -83,17 +83,21 @@ LLDBL fc_val_to_float(const void *val)
void fc_get_min(unsigned int num_bits)
{
CLEAR_BUFFER();
switch (num_bits)
{
/*
* Beware: FLT_MIN is the "Minimum normalised float",
* not the smallest number in arithmetic sense
*/
switch (num_bits) {
case 32:
value = FLT_MIN;
value = -FLT_MAX;
break;
case 64:
value = DBL_MIN;
value = -DBL_MAX;
break;
case 80:
default:
value = LDBL_MIN;
value = -LDBL_MAX;
break;
}
}
......@@ -152,8 +156,17 @@ void fc_calc(const void *a, const void *b, int opcode)
int fc_comp(const void *a, const void *b)
{
if (CAST_IN(a) == CAST_IN(b)) return 0;
else return (CAST_IN(a) > CAST_IN(b))?(1):(-1);
char buf1[40], buf2[40];
if (CAST_IN(a) == CAST_IN(b)) {
return 0;
}
else if (CAST_IN(a) > CAST_IN(b)) {
return 1;
}
else {
return -1;
}
}
char *fc_print_dec(const void *a, char *buf, int buflen)
......
......@@ -169,6 +169,9 @@ static int overflows(tarval *tv)
break;
case irms_float_number:
/*
* TODO: check NaNs
*/
if (fc_comp(tv->value, get_mode_max(tv->mode)->value) == 1) return 1;
if (fc_comp(tv->value, get_mode_min(tv->mode)->value) == -1) return 1;
break;
......@@ -630,20 +633,32 @@ tarval *tarval_convert_to(tarval *src, ir_mode *m)
break;
case irms_float_number:
switch (get_mode_sort(m)) {
case irms_float_number:
tv.mode = m;
tv.length = src->length;
tv.value = src->value;
if (overflows(&tv)) {
return tarval_bad;
}
return INSERT_TARVAL(&tv);
default:
break;
}
break;
case irms_int_number:
switch (get_mode_sort(m))
{
switch (get_mode_sort(m)) {
case irms_int_number:
case irms_character:
tv.mode = m;
tv.mode = m;
tv.length = src->length;
tv.value = src->value;
tv.value = src->value;
if (overflows(&tv))
{
return tarval_bad;
}
return INSERT_TARVAL(&tv);
case irms_internal_boolean:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment