def wrap_u64(vt, val): if vt == ValTypeI32: return int32(val) elif vt == ValTypeI64: return int64(val) elif vt == ValTypeF32: cov_val = struct.unpack('>f', struct.pack('>l', int64(val)))[0] if math.isnan(cov_val): return float32(val) else: return float32(cov_val) elif vt == ValTypeF64: cov_val = struct.unpack('>d', struct.pack('>q', int64(val)))[0] if math.isnan(cov_val): return float64(val) else: return float64(cov_val) else: raise Exception("unreachable")
def f32_const(vm, args): vm.push_f32(float32(args))
def f32_demote_f64(vm, _): vm.push_f32(float32(vm.pop_f64()))
def f32_convert_i64u(vm, _): vm.push_f32(float32(vm.pop_u64()))
def f32_convert_i64s(vm, _): vm.push_f32(float32(vm.pop_s64()))
def f32_convert_i32u(vm, _): vm.push_f32(float32(vm.pop_u32()))
def f32_convert_i32s(vm, _): vm.push_f32(float32(vm.pop_s32()))
def pop_f32(self): val = self.pop_numeric() val = struct.unpack('>f', struct.pack('>l', val))[0] return float32(val)