blob: e5ebf1e418224d7bd8956a78920da9e478840498 [file] [log] [blame]
(* WebAssembly-compatible type conversions to i64 implementation *)
let extend_i32_s x = Int64.of_int32 x
let extend_i32_u x = Int64.logand (Int64.of_int32 x) 0x00000000ffffffffL
let trunc_f32_s x =
if F32.ne x x then
raise Numeric_error.InvalidConversionToInteger
else
let xf = F32.to_float x in
if xf >= -.Int64.(to_float min_int) || xf < Int64.(to_float min_int) then
raise Numeric_error.IntegerOverflow
else
Int64.of_float xf
let trunc_f32_u x =
if F32.ne x x then
raise Numeric_error.InvalidConversionToInteger
else
let xf = F32.to_float x in
if xf >= -.Int64.(to_float min_int) *. 2.0 || xf <= -1.0 then
raise Numeric_error.IntegerOverflow
else if xf >= -.Int64.(to_float min_int) then
Int64.(logxor (of_float (xf -. 9223372036854775808.0)) min_int)
else
Int64.of_float xf
let trunc_f64_s x =
if F64.ne x x then
raise Numeric_error.InvalidConversionToInteger
else
let xf = F64.to_float x in
if xf >= -.Int64.(to_float min_int) || xf < Int64.(to_float min_int) then
raise Numeric_error.IntegerOverflow
else
Int64.of_float xf
let trunc_f64_u x =
if F64.ne x x then
raise Numeric_error.InvalidConversionToInteger
else
let xf = F64.to_float x in
if xf >= -.Int64.(to_float min_int) *. 2.0 || xf <= -1.0 then
raise Numeric_error.IntegerOverflow
else if xf >= -.Int64.(to_float min_int) then
Int64.(logxor (of_float (xf -. 9223372036854775808.0)) min_int)
else
Int64.of_float xf
let reinterpret_f64 = F64.to_bits