Skip to content

Commit

Permalink
Made some Math functions respect the number type
Browse files Browse the repository at this point in the history
Co-authored-by: Axanery <[email protected]>
  • Loading branch information
Lactozilla and Axanery committed Sep 18, 2024
1 parent 808646b commit 82bbe55
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions source/Engine/Bytecode/StandardLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 82bbe55

Please sign in to comment.