Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix division type coalescing #1580

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions OpenDreamRuntime/Procs/DMOpcodeHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2468,16 +2468,9 @@ private static DreamValue MultiplyValues(DreamValue first, DreamValue second) {
}

private static DreamValue DivideValues(DreamValue first, DreamValue second) {
if (first.IsNull) {
return new(0);
} else if (first.TryGetValueAsFloat(out var firstFloat) && second.TryGetValueAsFloat(out var secondFloat)) {
if (secondFloat == 0) {
throw new Exception("Division by zero");
}
return new(firstFloat / secondFloat);
} else {
throw new Exception("Invalid divide operation on " + first + " and " + second);
}
var lhand = first.UnsafeGetValueAsFloat(); // Coalesce objects to 0.
var rhand = second.TryGetValueAsFloat(out var rhandMaybe) ? rhandMaybe : 1;
return new(lhand / rhand);
}

private static DreamValue BitXorValues(DreamObjectTree objectTree, DreamValue first, DreamValue second) {
Expand Down
Loading