Skip to content

Commit

Permalink
WAT output: fix float output
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Apr 29, 2024
1 parent ab24656 commit d4c5423
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions compiler/lib/wasm/wa_wat_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,15 @@ let lookup_symbol ctx (x : symbol) =

let remove_nops l = List.filter ~f:(fun i -> not (Poly.equal i Nop)) l

let float64 _ f = Printf.sprintf "%h" f (*ZZZ*)
let float64 _ f =
match classify_float f with
| FP_normal | FP_subnormal | FP_zero | FP_nan -> Printf.sprintf "%h" f
| FP_infinite -> if Float.(f > 0.) then "inf" else "-inf"

let float32 _ f = Printf.sprintf "%h" f (*ZZZ*)
let float32 _ f =
match classify_float f with
| FP_normal | FP_subnormal | FP_zero | FP_nan -> Printf.sprintf "%h" f
| FP_infinite -> if Float.(f > 0.) then "inf" else "-inf"

let expression_or_instructions ctx in_function =
let rec expression e =
Expand All @@ -212,8 +218,8 @@ let expression_or_instructions ctx in_function =
(select
(fun _ i -> Int32.to_string i)
(fun _ i -> Int64.to_string i)
float64
float32
float64
op)
]
]
Expand Down

0 comments on commit d4c5423

Please sign in to comment.