Improved output for division by zero

This commit is contained in:
jan 2025-01-03 10:49:28 +01:00
parent 70fb53e87a
commit b498160c41
4 changed files with 6 additions and 5 deletions

View File

2
Cargo.lock generated
View File

@ -1813,7 +1813,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "svc16"
version = "0.7.1"
version = "0.7.2"
dependencies = [
"anyhow",
"clap",

View File

@ -1,6 +1,6 @@
[package]
name = "svc16"
version = "0.7.1"
version = "0.7.2"
edition = "2021"
authors = ["Jan Neuendorf"]
description = "An emulator for a simple virtual computer"

View File

@ -33,8 +33,8 @@ pub struct Engine {
#[derive(Debug, Error)]
pub enum EngineError {
#[error("Division by zero")]
ZeroDivision,
#[error("Division by zero {0}/0")]
ZeroDivision(u16),
#[error("Invalid instruction {0}")]
InvalidInstruction(u16),
@ -152,7 +152,8 @@ impl Engine {
}
DIV => {
if self.get(arg2) == 0 {
return Err(EngineError::ZeroDivision);
let numerator = self.get(arg1);
return Err(EngineError::ZeroDivision(numerator));
} else {
self.set(arg3, self.get(arg1).wrapping_div(self.get(arg2)));
self.advance_inst_ptr();