Skip to content

Commit eb8f9d0

Browse files
authored
[hlc] Fix warning truncation double to float (#12046)
1 parent 7726475 commit eb8f9d0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/generators/hl2c.ml

+5-1
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,11 @@ let generate_function ctx f =
811811
sexpr "%s = %ld" (reg r) code.ints.(idx)
812812
| OFloat (r,idx) ->
813813
let fstr = sprintf "%.19g" code.floats.(idx) in
814-
sexpr "%s = %s" (reg r) (if String.contains fstr '.' || String.contains fstr 'e' then fstr else fstr ^ ".")
814+
let fstr = (if String.contains fstr '.' || String.contains fstr 'e' then fstr else fstr ^ ".") in
815+
(match rtype r with
816+
| HF32 -> sexpr "%s = %sf" (reg r) fstr
817+
| _ -> sexpr "%s = %s" (reg r) fstr
818+
);
815819
| OBool (r,b) ->
816820
sexpr "%s = %s" (reg r) (if b then "true" else "false")
817821
| OBytes (r,idx) ->

0 commit comments

Comments
 (0)