Skip to content

Commit

Permalink
Fix division type coalescing
Browse files Browse the repository at this point in the history
  • Loading branch information
ike709 authored Dec 31, 2023
1 parent 186d10d commit 1adb41e
Showing 1 changed file with 3 additions and 10 deletions.
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

0 comments on commit 1adb41e

Please sign in to comment.