From: Michael Beck Date: Thu, 15 May 2003 15:44:20 +0000 (+0000) Subject: Fixed floating point minimum values, must be -*_MAX, not *_MIN ! X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=13c1bd27ef53f350af9a22f8c2701df53332125c;p=libfirm Fixed floating point minimum values, must be -*_MAX, not *_MIN ! Added floating point conversions... [r1216] --- diff --git a/ir/tv/fltcalc.c b/ir/tv/fltcalc.c index d8d07feb0..41cc094f5 100644 --- a/ir/tv/fltcalc.c +++ b/ir/tv/fltcalc.c @@ -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) diff --git a/ir/tv/tv.c b/ir/tv/tv.c index 1eccce86b..65c8f6387 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -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: