From 7611815a694d46a553cb5afb8d55bb2285caf8ac Mon Sep 17 00:00:00 2001 From: amylizzle Date: Mon, 22 Apr 2024 21:09:55 +0100 Subject: [PATCH] fix modulus --- Content.Tests/DMProject/Tests/Math/modulus.dm | 7 +++++++ OpenDreamRuntime/Procs/DMOpcodeHandlers.cs | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 Content.Tests/DMProject/Tests/Math/modulus.dm diff --git a/Content.Tests/DMProject/Tests/Math/modulus.dm b/Content.Tests/DMProject/Tests/Math/modulus.dm new file mode 100644 index 00000000000..451684135fe --- /dev/null +++ b/Content.Tests/DMProject/Tests/Math/modulus.dm @@ -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) diff --git a/OpenDreamRuntime/Procs/DMOpcodeHandlers.cs b/OpenDreamRuntime/Procs/DMOpcodeHandlers.cs index c41bd54bdad..e082f7cb1a5 100644 --- a/OpenDreamRuntime/Procs/DMOpcodeHandlers.cs +++ b/OpenDreamRuntime/Procs/DMOpcodeHandlers.cs @@ -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); } }