some fixes for xml dumper / still buggy.
[libfirm] / ir / tv / fltcalc.c
index 41cc094..df890d8 100644 (file)
@@ -156,7 +156,6 @@ void fc_calc(const void *a, const void *b, int opcode)
 
 int fc_comp(const void *a, const void *b)
 {
-  char buf1[40], buf2[40];
 
   if (CAST_IN(a) == CAST_IN(b)) {
     return 0;
@@ -171,11 +170,24 @@ int fc_comp(const void *a, const void *b)
 
 char *fc_print_dec(const void *a, char *buf, int buflen)
 {
+  int n;
+
 #ifdef USE_LONG_DOUBLE
-  snprintf(buf, buflen, "%1.30Lg", CAST_IN(a));
+  n = snprintf(buf, buflen, "%1.30Lg", CAST_IN(a));
 #else
-  snprintf(buf, buflen, "%1.30g", CAST_IN(a));
+  n = snprintf(buf, buflen, "%1.30g", CAST_IN(a));
 #endif
+
+  if (n > -1 && n < buflen) {
+    /*
+     * for some backends we always want to present 0 as 0.0
+     * as I could not find the best format to express this, add
+     * a .0 explicitely if not found
+     */
+    if (NULL == strrchr(buf, '.'))
+      strncat(buf, ".0", buflen);
+  }
+
   return buf;
 }