diff --git a/src/mlang/backend_compilers/bir_to_dgfip_c.ml b/src/mlang/backend_compilers/bir_to_dgfip_c.ml index d95477314..85b0103ac 100644 --- a/src/mlang/backend_compilers/bir_to_dgfip_c.ml +++ b/src/mlang/backend_compilers/bir_to_dgfip_c.ml @@ -97,10 +97,14 @@ let rec format_dexpr (dgfip_flags : Dgfip_options.flags) match de with | Done -> Format.fprintf fmt "1" | Dzero -> Format.fprintf fmt "0" - | Dlit f -> - (* Print literal floats as precisely as possible, without cluttering the - generated code *) - Format.fprintf fmt "%#.19g" f + | Dlit f -> ( + match Float.modf f with + | 0., _ -> + (* Print at least one decimal, distinction from integers *) + Format.fprintf fmt "%.1f" f + | _ -> + (* Print literal floats as precisely as possible *) + Format.fprintf fmt "%#.19g" f) | Dvar (evar, dflag) -> format_expr_var dgfip_flags vm fmt (evar, dflag) | Dand (de1, de2) -> format_dexpr fmt (Dbinop ("&&", de1, de2)) | Dor (de1, de2) -> format_dexpr fmt (Dbinop ("||", de1, de2)) diff --git a/src/mlang/m_frontend/mparser.mly b/src/mlang/m_frontend/mparser.mly index 7c359de8b..7cdb41892 100644 --- a/src/mlang/m_frontend/mparser.mly +++ b/src/mlang/m_frontend/mparser.mly @@ -412,33 +412,20 @@ expression: | OR { (Or, mk_position $sloc) } sum_expression: -| e = diff_expression { e } -| e1 = diff_expression op = sum_operator e2 = sum_expression { (Binop (op, e1, e2), mk_position $sloc) } - -diff_expression: | e = product_expression { e } -| e1 = diff_expression op = diff_operator e2 = product_expression { (Binop (op, e1, e2), mk_position $sloc) } +| e1 = sum_expression op = sum_operator e2 = product_expression { (Binop (op, e1, e2), mk_position $sloc) } sum_operator: | PLUS { (Add, mk_position $sloc) } - -diff_operator: | MINUS { (Sub, mk_position $sloc) } product_expression: -| e = div_expression { e } -| e1 = product_expression op = product_operator e2 = div_expression +| e = factor { e } +| e1 = product_expression op = product_operator e2 = factor { (Binop (op, e1, e2), mk_position $sloc) } product_operator: | TIMES { (Mul, mk_position $sloc) } - -div_expression: -| e = factor { e } -| e1 = div_expression op = div_operator e2 = factor -{ (Binop (op, e1, e2), mk_position $sloc) } - -div_operator: | DIV { (Div, mk_position $sloc) } table_index_name: