Page MenuHomeFeedback Tracker

Floating point precision is very inaccurate.
Feedback, WishlistPublic

Description

33.8025-33=0.802502 over
33.8125-33=0.8125
correct
33.8225-33=0.822498 under
33.8325-33=0.8325
correct
33.8425-33=0.842499 under
33.8525-33=0.852501
over

Details

Legacy ID
1700025985
Severity
None
Resolution
Reopened
Reproducibility
Always
Category
Scripting
Steps To Reproduce

Just do any basic subtraction against a floating point.

Additional Information

This shouldn't be an issue in a game engine in 2014.

Event Timeline

Nou edited Steps To Reproduce. (Show Details)Apr 22 2014, 8:30 AM
Nou edited Additional Information. (Show Details)
Nou set Category to Scripting.
Nou set Reproducibility to Always.
Nou set Severity to None.
Nou set Resolution to Reopened.
Nou set Legacy ID to 1700025985.May 7 2016, 6:28 PM
Nou edited a custom field.
Nou added a subscriber: Nou.May 7 2016, 6:28 PM
Nou added a comment.Apr 22 2014, 8:35 AM

Also subtraction on large numbers is inaccurate: 33000011-33000000 = 12.

ocf81 added a subscriber: ocf81.May 7 2016, 6:28 PM

I would really like you to read http://floating-point-gui.de/ and then understand that FP arithmetic will not ever return precise decimal results. That being said, I would really like to know the precision used in the game engine.

The Int calculation is somewhat puzzling though. That should not happen.

zx64 added a subscriber: zx64.May 7 2016, 6:28 PM
zx64 added a comment.Apr 22 2014, 1:41 PM

Looks like the game is using single precision: http://codepad.org/hcwPbKPf (I think you'll find a few game engines using single precision in 2014)

Also looks like (as with JavaScript) there is strictly no integer type, just operations on floats: http://codepad.org/YK8G2YV0

I am, of course, not implying that double precision would give exact answers, just the appearance of meeting expectations in these simple cases.

dazhbog added a subscriber: dazhbog.May 7 2016, 6:28 PM

zx64: correct on both accounts.

If this behavior breaks some specific mission or mechanic please report it as a separate issue.