def __trunc_sat_s(z, n): if math.isnan(z): return 0 min_value = -(int64(1) << (n - 1)) max_value = (int64(1) << (n - 1)) - 1 if z == -math.inf: return min_value if math.isinf(z): return max_value x = math.trunc(z) if x < float64(min_value): return min_value elif x >= float64(max_value): return max_value else: return int64(x)
def pop_f64(self): val = self.pop_numeric() try: val = struct.unpack('>d', struct.pack('>q', val))[0] except struct.error: val = struct.unpack('>d', struct.pack('>Q', val))[0] return float64(val)
def wrap_u64(vt, val): if vt == ValTypeI32: return int32(val) elif vt == ValTypeI64: return int64(val) elif vt == ValTypeF32: val = struct.unpack('>f', struct.pack('>l', int64(val)))[0] return float32(val) elif vt == ValTypeF64: val = struct.unpack('>d', struct.pack('>q', int64(val)))[0] return float64(val) else: raise Exception("unreachable")
def __trunc_sat_u(z, n): if math.isnan(z): return 0 if z == -math.inf: return 0 max_value = (uint64(1) << n) - 1 if math.isinf(z): return max_value x = math.trunc(z) if x < 0: return 0 elif x >= float64(max_value): return max_value else: return uint64(x)
def f64_const(vm, args): vm.push_f64(float64(args))
def f64_promote_f32(vm, _): vm.push_f64(float64(vm.pop_f32()))
def f64_convert_i64u(vm, _): vm.push_f64(float64(vm.pop_u64()))
def f64_convert_i64s(vm, _): vm.push_f64(float64(vm.pop_s64()))
def f64_convert_i32u(vm, _): vm.push_f64(float64(vm.pop_u32()))
def f64_convert_i32s(vm, _): vm.push_f64(float64(vm.pop_s32()))