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 returns 0.001 #61956

Open
lyuma opened this issue Jun 12, 2022 · 5 comments
Open

Division in inspector returns 0.001 #61956

lyuma opened this issue Jun 12, 2022 · 5 comments

Comments

@lyuma
Copy link
Contributor

lyuma commented Jun 12, 2022

Godot version

4.0.dev b9375ea

System information

Windows 10.0.19044.1706

Issue description

I wanted to divide an imported file by 64, so I typed 1/64 into the root scale and it showed 0.001.
Typing 1/64.0 gives roughly the correct answer.

I think it's treating it as integer division, but this is not correct because these variables are floats.

Steps to reproduce

  1. Add a new scene with a Node3D.
  2. Type 1/64 into the Scale field.
  3. It shows 0 instead
  4. Type 1/64.0 into the inspector. Now it shows roughly the correct answer.

Minimal reproduction project

None. It happens in an empty project

@Calinou
Copy link
Member

Calinou commented Jun 12, 2022

This is expected behavior of the Expression evaluator. Integer division is performed if both operands are integers. The type of the property in the inspector has no bearing on Expression's behavior.

@lyuma
Copy link
Contributor Author

lyuma commented Jun 12, 2022

This may be expected behavior currently. That's why I'm filing a bug. It's wrong.

@lyuma
Copy link
Contributor Author

lyuma commented Jun 12, 2022

If we want this behavior, then the inspector should display all floating points ending with ".0". Having an inspector which treats input differently than output is wrong.

For example, I have a floating point which shows as 10000, It would be wrong to treat it as integer upon reading it back in.

@Calinou
Copy link
Member

Calinou commented Jun 12, 2022

If we want this behavior, then the inspector should display all floating points ending with ".0".

This is done by #45303, but it hasn't been merged yet.

As for adding an actual integer division operator (such as //), there's been a long discussion here, but it ended up being rejected in the end.

@hsandt
Copy link
Contributor

hsandt commented May 16, 2023

I see the point in displaying numbers with .0, however in my case (and the OP's too) it wouldn't fix the issue, as I'm inputting the whole expression.

Ex:

  1. The field shows "1.0". I edit the field and add "/2" at the end. It gives 0.5 as expected.
  2. The field shows "2.0". I edit the field but I enter a whole new expression such as "1/2" by myself. The result is now 0 instead of 0.5.

While it makes sense from an operational point of view, I often use divisions for things like fraction of textures for UV (1/8, 1/16...) and inverse (frequency = 1/duration).

Is there a way we could still interpret divisions inside a float field as if all numbers were float, Lua style?

Well, at least I know the trick now, and will add a decimal point . when I need that. But not sure if my fellow designers will get that.

I was looking for a place to document this, but https://docs.godotengine.org/en/stable/tutorials/editor/inspector_dock.html doesn't mention numerical expressions at all and https://docs.godotengine.org/en/stable/tutorials/scripting/evaluating_expressions.html (which is probably used for the inspector too) is on code side.

EDIT: since the 0.001 is a special case when value is clamped, should we rename the issue to a more generic title like Inspector division on integers in float field still applies Euclidian division, maybe with an example if you want to make it clear like (1/2 = 0) ?

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

No branches or pull requests

3 participants