Procházet zdrojové kódy

Added trailing zero after rounded floating point number stringification

Taddeus Kroes před 12 roky
rodič
revize
ce994bbdcd
1 změnil soubory, kde provedl 7 přidání a 1 odebrání
  1. 7 1
      stringify.ml

+ 7 - 1
stringify.ml

@@ -5,6 +5,12 @@ let tab = "    "
 (* string -> string *)
 let indent = Str.global_replace (Str.regexp "^\\(.\\)") (tab ^ "\\1")
 
+(* Add a trailing zero to a float stringification
+ * float -> string *)
+let float2string f = match string_of_float f with
+    | s when s.[String.length s - 1] = '.' -> s ^ "0"
+    | s -> s
+
 (* operator -> string *)
 let op2str = function
     | Neg -> "-"
@@ -97,7 +103,7 @@ and node2str node =
     (* Expressions *)
     | BoolConst (b, _) -> string_of_bool b
     | IntConst (i, _) -> string_of_int i
-    | FloatConst (f, _) -> string_of_float f
+    | FloatConst (f, _) -> float2string f
     | ArrayConst (dims, _) -> "[" ^ concat ", " dims ^ "]"
     | Var (v, _) -> v
     | Deref (name, dims, _) -> name ^ (str (ArrayConst (dims, noloc)))