summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-07-19 15:07:49 +0200
committerGitHub <noreply@github.com>2019-07-19 15:07:49 +0200
commitf796779f7c89cd2c92bc4531e5e90f49acda30f9 (patch)
tree96bffa75633d0a624f788c2e8bd402937b46c3b0 /core
parent2ca3e47d66fe3f3d849e2084d516949c84011f4b (diff)
parenta60f242982d70e85a5b2c182eb3289b2fa7812e1 (diff)
Merge pull request #23310 from aaronfranke/posmod-int
Add integer posmod and rename default arg names
Diffstat (limited to 'core')
-rw-r--r--core/math/expression.cpp8
-rw-r--r--core/math/expression.h1
-rw-r--r--core/math/math_funcs.h7
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; }