Skip to content

Commit

Permalink
fix modulus
Browse files Browse the repository at this point in the history
  • Loading branch information
amylizzle committed Apr 22, 2024
1 parent 1fe1013 commit 7611815
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Content.Tests/DMProject/Tests/Math/modulus.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/proc/RunTest()
ASSERT(10 % 5 == 0)
ASSERT(20 % 60 == 20)
ASSERT(30.8 % 30 == 0)
ASSERT(30.1 % 30 == 0)
ASSERT(5 % 2.5 == 1)
ASSERT(60 % 62.5 == 60)
6 changes: 3 additions & 3 deletions OpenDreamRuntime/Procs/DMOpcodeHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2612,9 +2612,9 @@ private static DreamValue BitXorValues(DreamObjectTree objectTree, DreamValue fi
}

private static DreamValue ModulusValues(DreamValue first, DreamValue second) {
if (first.TryGetValueAsFloat(out var firstFloat) || first.IsNull) {
if (second.TryGetValueAsFloat(out var secondFloat)) {
return new DreamValue(firstFloat % secondFloat);
if (first.TryGetValueAsInteger(out var firstInt) || first.IsNull) {
if (second.TryGetValueAsInteger(out var secondInt)) {
return new DreamValue(firstInt % secondInt);
}
}

Expand Down

0 comments on commit 7611815

Please sign in to comment.