Godot: Allow remainder (%) operator to use floats

Created on 17 Mar 2019  路  4Comments  路  Source: godotengine/godot

Godot version:
3.1

OS/device including version:
Windows 10 x64

Issue description:
While in Python I can have for example 2.0 % 1.01 resulting in 0.99, in GDScript I get this error: Invalid operands 'float' and 'float' in operator '%'.
I know fmod can do this, but this suggestion is to make it more similar to Python.

archived

Most helpful comment

There's fmod(...) for that and GDScript's intention is not being as similar to Python as possible.

All 4 comments

There's fmod(...) for that and GDScript's intention is not being as similar to Python as possible.

Gdscript translates to C calls which are not supports such syntax sugar, by doing so we need to write a cumbersome logic for little gain

Duplicate of #10004.

This was already rejected by @reduz with:

it's not a bug, it's a feature (tm),intended to avoids mistakes. Use fmod() for floats.

And I still think that's the right approach. Having remainder work for both floats and ints can lead to bugs which are hard to debug (like giving you a float as result for an operation where you expected an int), so it's better to be explicit.

Ok, no problems. Closing.

Was this page helpful?
0 / 5 - 0 ratings