+1 vote

Was curious about this function, and why it's different than fmod(). It says something vague about wrapping equally in negative and positive.

Can anyone share what it's about?

Thanks.

in Engine by (4,944 points)

1 Answer

0 votes
print(fmod(-7,10)) # -7
print(fposmod(-7,10)) #3

they behave diffrent when it comes to negative values. Afaik the first one is the one for euclidean divison.

by (289 points)

Yeah the implementation is:

return (p_x>=0) ? Math::fmod(p_x,p_y) : p_y-Math::fmod(-p_x,p_y);

I'm wondering about it's application though. Does it go by another name?

Mathematically, the function that returns -7 is called the Remainder function (Rem) and the function that returns 3 is called the Modulus function (Mod). It's more common to implement the Remainer instead of the Modulus as it is easier to write and works fast for positive values.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories