Skip to content

Commit 74d4b10

Browse files
committed
WAT output: signed nan
Not very important since it is only used for debugging
1 parent f234fdb commit 74d4b10

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

compiler/lib-wasm/wat_output.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,22 @@ let float64 _ f =
328328
match classify_float f with
329329
| FP_normal | FP_subnormal | FP_zero -> Printf.sprintf "%h" f
330330
| FP_nan ->
331+
let f = Int64.(bits_of_float f) in
331332
Printf.sprintf
332-
"nan:0x%Lx"
333-
Int64.(logand (bits_of_float f) (of_int ((1 lsl 52) - 1)))
333+
"%snan:0x%Lx"
334+
(if Int64.( >= ) f 0L then "" else "-")
335+
Int64.(logand f (of_int ((1 lsl 52) - 1)))
334336
| FP_infinite -> if Float.(f > 0.) then "inf" else "-inf"
335337

336338
let float32 _ f =
337339
match classify_float f with
338340
| FP_normal | FP_subnormal | FP_zero -> Printf.sprintf "%h" f
339341
| FP_nan ->
342+
let f = Int32.(bits_of_float f) in
340343
Printf.sprintf
341-
"nan:0x%lx"
342-
Int32.(logand (bits_of_float f) (of_int ((1 lsl 23) - 1)))
344+
"%snan:0x%lx"
345+
(if Int32.( >= ) f 0l then "" else "-")
346+
Int32.(logand f (of_int ((1 lsl 23) - 1)))
343347
| FP_infinite -> if Float.(f > 0.) then "inf" else "-inf"
344348

345349
let expression_or_instructions ctx st in_function =

0 commit comments

Comments
 (0)