From a6af244080d05a7cac31e419a2b8058325c8c99b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Mon, 29 Apr 2024 13:23:28 +0200 Subject: [PATCH] use more correct logic for `mod` --- ic10emu/src/interpreter.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ic10emu/src/interpreter.rs b/ic10emu/src/interpreter.rs index d3bd663..76006c6 100644 --- a/ic10emu/src/interpreter.rs +++ b/ic10emu/src/interpreter.rs @@ -1745,7 +1745,11 @@ impl IC { } = reg.as_register(this, inst, 1)?; let a = a.as_value(this, inst, 2)?; let b = b.as_value(this, inst, 1)?; - this.set_register(indirection, target, ((a % b) + b) % b)?; + let mut m = (a % b); + if m < 0.0 { + m += b; + } + this.set_register(indirection, target, m)?; Ok(()) } oprs => Err(ICError::mismatch_operands(oprs.len(), 3)),