Browse Source

* 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.

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

Ankit Jain 20 years ago
parent
commit
0b072add5f
4 changed files with 44 additions and 8 deletions
  1. 8 0
      mono/dis/ChangeLog
  2. 10 4
      mono/dis/dis-cil.c
  3. 24 4
      mono/dis/get.c
  4. 2 0
      mono/dis/get.h

+ 8 - 0
mono/dis/ChangeLog

@@ -1,3 +1,11 @@
+2006-01-25  Ankit Jain  <[email protected]>
+
+	* 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  <[email protected]>
 	    Raja R Harinath  <[email protected]>
 

+ 10 - 4
mono/dis/dis-cil.c

@@ -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;
 		}

+ 24 - 4
mono/dis/get.c

@@ -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:

+ 2 - 0
mono/dis/get.h

@@ -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
  */