From 82bbe5549fd70af300f9848fd339c9708a00c953 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Wed, 18 Sep 2024 20:06:09 -0300 Subject: [PATCH] Made some Math functions respect the number type Co-authored-by: Axanery <41282531+Axanery@users.noreply.github.com> --- source/Engine/Bytecode/StandardLibrary.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/source/Engine/Bytecode/StandardLibrary.cpp b/source/Engine/Bytecode/StandardLibrary.cpp index 4cecfb4..d96410f 100644 --- a/source/Engine/Bytecode/StandardLibrary.cpp +++ b/source/Engine/Bytecode/StandardLibrary.cpp @@ -7364,7 +7364,10 @@ VMValue Math_Direction(int argCount, VMValue* args, Uint32 threadID) { */ VMValue Math_Abs(int argCount, VMValue* args, Uint32 threadID) { CHECK_ARGCOUNT(1); - return DECIMAL_VAL(Math::Abs(GET_ARG(0, GetDecimal))); + if (IS_INTEGER(args[0])) + return INTEGER_VAL((int)Math::Abs(GET_ARG(0, GetInteger))); + else + return DECIMAL_VAL(Math::Abs(GET_ARG(0, GetDecimal))); } /*** * Math.Min @@ -7376,8 +7379,10 @@ VMValue Math_Abs(int argCount, VMValue* args, Uint32 threadID) { */ VMValue Math_Min(int argCount, VMValue* args, Uint32 threadID) { CHECK_ARGCOUNT(2); - // respect the type of number - return DECIMAL_VAL(Math::Min(GET_ARG(0, GetDecimal), GET_ARG(1, GetDecimal))); + if (IS_INTEGER(args[0]) && IS_INTEGER(args[1])) + return INTEGER_VAL((int)Math::Min(GET_ARG(0, GetDecimal), GET_ARG(1, GetDecimal))); + else + return DECIMAL_VAL(Math::Min(GET_ARG(0, GetDecimal), GET_ARG(1, GetDecimal))); } /*** * Math.Max @@ -7389,7 +7394,10 @@ VMValue Math_Min(int argCount, VMValue* args, Uint32 threadID) { */ VMValue Math_Max(int argCount, VMValue* args, Uint32 threadID) { CHECK_ARGCOUNT(2); - return DECIMAL_VAL(Math::Max(GET_ARG(0, GetDecimal), GET_ARG(1, GetDecimal))); + if (IS_INTEGER(args[0]) && IS_INTEGER(args[1])) + return INTEGER_VAL((int)Math::Max(GET_ARG(0, GetDecimal), GET_ARG(1, GetDecimal))); + else + return DECIMAL_VAL(Math::Max(GET_ARG(0, GetDecimal), GET_ARG(1, GetDecimal))); } /*** * Math.Clamp @@ -7402,7 +7410,10 @@ VMValue Math_Max(int argCount, VMValue* args, Uint32 threadID) { */ VMValue Math_Clamp(int argCount, VMValue* args, Uint32 threadID) { CHECK_ARGCOUNT(3); - return DECIMAL_VAL(Math::Clamp(GET_ARG(0, GetDecimal), GET_ARG(1, GetDecimal), GET_ARG(2, GetDecimal))); + if (IS_INTEGER(args[0]) && IS_INTEGER(args[1]) && IS_INTEGER(args[2])) + return INTEGER_VAL((int)Math::Clamp(GET_ARG(0, GetDecimal), GET_ARG(1, GetDecimal), GET_ARG(2, GetDecimal))); + else + return DECIMAL_VAL(Math::Clamp(GET_ARG(0, GetDecimal), GET_ARG(1, GetDecimal), GET_ARG(2, GetDecimal))); } /*** * Math.Sign