Fixed floating point minimum values, must be -*_MAX, not *_MIN !
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Thu, 15 May 2003 15:44:20 +0000 (15:44 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Thu, 15 May 2003 15:44:20 +0000 (15:44 +0000)
Added floating point conversions...

[r1216]

ir/tv/fltcalc.c
ir/tv/tv.c

index d8d07fe..41cc094 100644 (file)
@@ -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)
index 1eccce8..65c8f63 100644 (file)
@@ -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: