mirror of
https://github.com/JanNeuendorf/SVC16.git
synced 2025-06-03 01:50:18 +00:00
Improved output for division by zero
This commit is contained in:
parent
70fb53e87a
commit
b498160c41
0
.intentionally-empty-file.o
Normal file
0
.intentionally-empty-file.o
Normal file
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1813,7 +1813,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "svc16"
|
||||
version = "0.7.1"
|
||||
version = "0.7.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
@ -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"
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user