Skip to content

Commit 192637b

Browse files
committed
Wat output: preserve the NaN payload.
1 parent 0094c06 commit 192637b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

compiler/lib-wasm/wat_output.ml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,20 @@ let remove_nops l = List.filter ~f:(fun i -> not (Poly.equal i Nop)) l
303303

304304
let float64 _ f =
305305
match classify_float f with
306-
| FP_normal | FP_subnormal | FP_zero | FP_nan -> Printf.sprintf "%h" f
306+
| FP_normal | FP_subnormal | FP_zero -> Printf.sprintf "%h" f
307+
| FP_nan ->
308+
Printf.sprintf
309+
"nan:0x%Lx"
310+
Int64.(logand (bits_of_float f) (of_int ((1 lsl 52) - 1)))
307311
| FP_infinite -> if Float.(f > 0.) then "inf" else "-inf"
308312

309313
let float32 _ f =
310314
match classify_float f with
311-
| FP_normal | FP_subnormal | FP_zero | FP_nan -> Printf.sprintf "%h" f
315+
| FP_normal | FP_subnormal | FP_zero -> Printf.sprintf "%h" f
316+
| FP_nan ->
317+
Printf.sprintf
318+
"nan:0x%lx"
319+
Int32.(logand (bits_of_float f) (of_int ((1 lsl 23) - 1)))
312320
| FP_infinite -> if Float.(f > 0.) then "inf" else "-inf"
313321

314322
let expression_or_instructions ctx st in_function =

0 commit comments

Comments
 (0)