* get.c (stringify_double): New. Fix printing of float/doubles to enable
authorAnkit Jain <radical@corewars.org>
Wed, 25 Jan 2006 14:59:46 +0000 (14:59 -0000)
committerAnkit Jain <radical@corewars.org>
Wed, 25 Jan 2006 14:59:46 +0000 (14:59 -0000)
roundtripping.
* get.h (stringify_double): Add new function.
(get_constant): Use stringify_double.
* dis-cil.c (disassemble_cil): Likewise.

svn path=/trunk/mono/; revision=56045

mono/dis/ChangeLog
mono/dis/dis-cil.c
mono/dis/get.c
mono/dis/get.h

index 5b0dc598edb23cffa6e243b2bd64d77f37d9f7c3..4deeb2ea45b0821b1093a33865d7c022f9aae7d5 100644 (file)
@@ -1,3 +1,11 @@
+2006-01-25  Ankit Jain  <jankit@novell.com>
+
+       * get.c (stringify_double): New. Fix printing of float/doubles to enable
+       roundtripping.
+       * get.h (stringify_double): Add new function.
+       (get_constant): Use stringify_double.
+       * dis-cil.c (disassemble_cil): Likewise.
+       
 2006-01-25  Ankit Jain  <jankit@novell.com>
            Raja R Harinath  <rharinath@novell.com>
 
index 950511107eb6a3592f8c7ad26813c8cbe53050c6..65713e97367aa9098726c25cafdb7cf2ada96773 100644 (file)
@@ -192,8 +192,11 @@ dissasemble_cil (MonoImage *m, MonoMethodHeader *mh, MonoGenericContext *context
                                fprintf (output, "(00 00 00 00 00 00 f0 7f)"); /* positive infinity */
                        else if (isnan (r))
                                fprintf (output, "(00 00 00 00 00 00 f8 ff)"); /* NaN */
-                       else
-                               fprintf (output, "%.20g", r);
+                       else {
+                               char *str = stringify_double (r);
+                               fprintf (output, str);
+                               g_free (str);
+                       }
                        ptr += 8;
                        break;
                }
@@ -298,8 +301,11 @@ dissasemble_cil (MonoImage *m, MonoMethodHeader *mh, MonoGenericContext *context
                                fprintf (output, "(00 00 80 7f)"); /* positive infinity */
                        else if (isnan (f))
                                fprintf (output, "(00 00 c0 ff)"); /* NaN */
-                       else
-                               fprintf (output, "%.20g", (double) f);
+                       else {
+                               char *str = stringify_double ((double) f);
+                               fprintf (output, str);
+                               g_free (str);
+                       }
                        ptr += 4;
                        break;
                }
index e71a073b90215d6d06fc8a2ad8616aba37ff3f4e..f6a68dfd0253a1a391e9c5b19cd9cb26a95b37f4 100644 (file)
@@ -2145,6 +2145,19 @@ get_encoded_user_string_or_bytearray (const unsigned char *ptr, int len)
        return result;
 }
 
+char *
+stringify_double (double r)
+{
+       char *ret, *ptr;
+
+       ret = g_strdup_printf ("%.17g.", r);
+       ptr = ret + strlen (ret) - 1;
+       if (strchr (ret, '.') != ptr)
+               *ptr = '\0';
+
+       return ret;
+}
+
 /**
  * get_constant:
  * @m: metadata context
@@ -2199,10 +2212,14 @@ get_constant (MonoImage *m, MonoTypeEnum t, guint32 blob_index)
 #else
                normal = isnormal (r);
 #endif
-               if (!normal)
+               if (!normal) {
                        return g_strdup_printf ("float32(0x%08x)", read32 (ptr));
-               else
-                       return g_strdup_printf ("float32(%.20g)", r);
+               } else {
+                       char *str = stringify_double ((double) r);
+                       char *ret = g_strdup_printf ("float32(%s)", str);
+                       g_free (str);
+                       return ret;
+               }
        }       
        case MONO_TYPE_R8: {
                gboolean normal;
@@ -2221,7 +2238,10 @@ get_constant (MonoImage *m, MonoTypeEnum t, guint32 blob_index)
                        high = read32 (ptr + 4);
                        return g_strdup_printf ("float64(0x%08x%08x)", high, low);
                } else {
-                       return g_strdup_printf ("float64(%.20g)", r);
+                       char *str = stringify_double (r);
+                       char *ret = g_strdup_printf ("float64(%s)", str);
+                       g_free (str);
+                       return ret;
                }
        }
        case MONO_TYPE_STRING:
index f3ab002d266c0845c7258c29a73ac9aaedcb8272..76f4f5304f4c8fb023312493e8d21aa1abd03f17 100644 (file)
@@ -73,6 +73,8 @@ const char *get_blob_encoded_size      (const char *ptr, int *size);
 
 MonoTypeEnum get_field_literal_type (MonoImage *m, guint32 blob_signature);
 
+char *stringify_double (double r);
+
 /**
  * This is called to initialize the table containing keyword names
  */