Comparing doubles often fails #47

Closed
opened 2019-08-10 18:50:05 +00:00 by orange451 · 1 comment
orange451 commented 2019-08-10 18:50:05 +00:00 (Migrated from github.com)

Comparing double values using luaj often fails, since it uses a simple comparison. See:
https://howtodoinjava.com/java/basics/correctly-compare-float-double/

Would something like this be possible to be put into the current version of LuaJ?

For example, I'm keeping track of how a variable changes in my program. I set the player height to 1.0. In the next frame I set his height to 1.0 again. On height change, I check the current value of height in the lua object (which should be 1.0 but it's now 0.999999999). 0.9999999 is not equal to 1.0, so it thinks the player height changed. Sure I can work around this, but I have a few thousand variables being checked, and would rather not change them all like this.

Comparing double values using luaj often fails, since it uses a simple comparison. See: https://howtodoinjava.com/java/basics/correctly-compare-float-double/ Would something like this be possible to be put into the current version of LuaJ? For example, I'm keeping track of how a variable changes in my program. I set the player height to 1.0. In the next frame I set his height to 1.0 again. On height change, I check the current value of height in the lua object (which should be 1.0 but it's now 0.999999999). 0.9999999 is not equal to 1.0, so it thinks the player height changed. Sure I can work around this, but I have a few thousand variables being checked, and would rather not change them all like this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: open-autonomous-connection/luaj#47