Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Division in inspector rounds result #25856

Closed
breakmt opened this issue Feb 13, 2019 · 3 comments
Closed

Division in inspector rounds result #25856

breakmt opened this issue Feb 13, 2019 · 3 comments
Labels

Comments

@breakmt
Copy link

breakmt commented Feb 13, 2019

Godot version:
3.1 beta 4

Issue description:
Example:

  1. Node2D -> Inspector -> Transform
  2. In Scale.X write 1/2 and hit Enter

Result: value is 0

Expected: value is 0.5

Note:
I'm not sure if this expected behavior, but in my opinion as "scale" is vector2 and it contains X and Y which are float, so the result of division calculation should be float as well. But right now result is rounded.

@akien-mga
Copy link
Member

That's intended behaviour, most programming languages work this way. If you divide an integer by an integer, you get an integer (and thus the integral part of the division).

Use 1.0/2, 1/2.0 or 1.0/2.0 if you want a float.

@AlfishSoftware
Copy link

That's intended behaviour

That's terrible behavior, though. The inspector is not a programming language and a field in the inspector is not a coding area - if anything, people will see it like a calculator.
This is an important necessary feature that should work predictably; it shouldn't be replaced with irregular behavior just because of some technicality. This badly hurts usability, even for coders and will confuse beginners.

Often you want to quickly divide a bunch of values to make adjustments in a batch, without having to pay attention to the actual value. If the field is float, then adding /4 at the end of the current value should give me a float division always. Current behavior is awful because this will depend on the current value. If it shows 1.01 then I get it right, but if it happens to show 1 instead, then I won't get 1.0/4 = 0.25, but an integer division nobody would expect on a float field.

I'm not asking to "solve" this by showing 1.0 unnecessarily.
What should happen is whatever parser that evaluates this should either:

  • parse all numeric literals as the field type - if the field is long, then it's only fair that it would make integer division
  • parse all numeric literals as double, like in JS, then cast the calculation result to the field type at the end
  • or just cast values to double before all divisions

If you really want to allow integer/floor division in float fields, then make a // operator like in Python, or a div function.

@akien-mga Please reopen.

@AThousandShips
Copy link
Member

AThousandShips commented Jul 6, 2023

If you want to change the behaviour open a proposal though I'm pretty sure there's one already if you search, this is for bugs and shouldn't be reopened

See:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants