diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/math/expression.cpp | 8 | ||||
-rw-r--r-- | core/math/expression.h | 1 | ||||
-rw-r--r-- | core/math/math_funcs.h | 7 |
3 files changed, 16 insertions, 0 deletions
diff --git a/core/math/expression.cpp b/core/math/expression.cpp index b52658e2cf..2786229cf3 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -52,6 +52,7 @@ const char *Expression::func_name[Expression::FUNC_MAX] = { "sqrt", "fmod", "fposmod", + "posmod", "floor", "ceil", "round", @@ -175,6 +176,7 @@ int Expression::get_func_argument_count(BuiltinFunc p_func) { case MATH_ATAN2: case MATH_FMOD: case MATH_FPOSMOD: + case MATH_POSMOD: case MATH_POW: case MATH_EASE: case MATH_STEPIFY: @@ -283,6 +285,12 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant VALIDATE_ARG_NUM(1); *r_return = Math::fposmod((double)*p_inputs[0], (double)*p_inputs[1]); } break; + case MATH_POSMOD: { + + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + *r_return = Math::posmod((int)*p_inputs[0], (int)*p_inputs[1]); + } break; case MATH_FLOOR: { VALIDATE_ARG_NUM(0); diff --git a/core/math/expression.h b/core/math/expression.h index 1113bb6587..03a2bb70e6 100644 --- a/core/math/expression.h +++ b/core/math/expression.h @@ -51,6 +51,7 @@ public: MATH_SQRT, MATH_FMOD, MATH_FPOSMOD, + MATH_POSMOD, MATH_FLOOR, MATH_CEIL, MATH_ROUND, diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 0e3bd8a318..b6398712e4 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -198,6 +198,13 @@ public: value += 0.0; return value; } + static _ALWAYS_INLINE_ int posmod(int p_x, int p_y) { + int value = p_x % p_y; + if ((value < 0 && p_y > 0) || (value > 0 && p_y < 0)) { + value += p_y; + } + return value; + } static _ALWAYS_INLINE_ double deg2rad(double p_y) { return p_y * Math_PI / 180.0; } static _ALWAYS_INLINE_ float deg2rad(float p_y) { return p_y * Math_PI / 180.0; } |