Skip to content

Instantly share code, notes, and snippets.

@sfpgmr sfpgmr/itof.wat
Created Aug 12, 2018

Embed
What would you like to do?
IEEE754 float32/64のビットパターンを持つ1つ/2つの32ビット値を元にして、32/64bit floatを返すwasm関数
(module
(export "i32tof32" $i32tof32)
(export "i64tof64" $i64tof64)
;; IEE754 float32のビットパターンを持つ32ビット整数値をf32に変換する
(func $i32tof32 (param $i i32) (param $minus i32) (result f32)
(f32.reinterpret/i32
(i32.xor
(get_local $i)
(get_local $minus)
)
)
)
;; IEEE754 float64のビットパターンを持つ2つの32ビット値(high,low)を元にして、64bit floatを返す
(func $i64tof64 (param $low i32) (param $high i32) (param $minus i32) (result f64)
(f64.reinterpret/i64
(i64.xor
(i64.or
(i64.shl
(i64.extend_u(get_local $high))
(i64.const 32)
)
(i64.extend_u (get_local $low))
)
(i64.shl
(i64.extend_u(get_local $minus))
(i64.const 32)
)
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.