Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Floating point addition error

Hi guys, I'm having a somewhat unusual problem adding floating point numbers. The issue occurs when I try to add low decimal place values to to floats above 2,100,000 as they simply stop adding to the number; I also get issues when adding low whole numbers to large floating point values, for example if i try to add a float of 10.0 to a float of 52,100,440 then it will only add 8 instead... I'm at lose and this has broken our scoring system. More details below:

[Information on the Game and our floating point scoring system] We have a game with a scoring system where the player earns points for killing the bad guys the idea is to give the play really big stupidly large values for this. The scores are stored as floating point numbers but only displayed on the screen as whole numbers (the display is rounded by the ToText node in blueprints, to remove the decimal values, the raw score itself is never rounded), we're using floating points to store the scores so that we can multipliers (with decimal places) as well based on the number of enemies killed (the multiplier increases by 0.2 for each enemy killed and will reduce back to 1 if no enemies are killed in the last five seconds). The scores are designed to get pretty big, into the hundreds of millions. We want the score to be permanently in motion so for each tick that the player is moving we were adding 0.1 to the score. Score is stored in the GameState and the functions for added to the score and the multiplier are also in the GameState.

[Problems] When the score get's over 2,100,000 the decimal place values stop being added to it and and the score stops ticking up. I've since tried which larger numbers and i'm getting some real odd results (see the attached output log below).

[Tests] I set up some quick controls for adding 50,000 | 100,000 | 10,000,000 points to the score and augmented the scoring system to add 10 points to the score for each tick in which the player is in motion. The 10 points for motion get added just fine until I force the score above 52,100,440 after which 8 points are added instead of 10 even though it is still being told to add 10 (see output log). This continues until the score until the score is forced up above 152,100,576 after which 16 points are added when it is told to add 10. After pushing the score to 412,100,672 no points are added when it is told to add 10.

The Game is currently in 4.16.0. This issue occurs both in engine and in the build. All of the functionality is made in blueprints, but it is a code project.

Any suggestions would be really appreciated as I'm at a lose here. Thanks.

I've added a quick video on YouTube which shows the issue and the blueprints in question, hope it helps: https://youtu.be/hrMsuESQLhg

[Link to the Output Log] link text

Product Version: UE 4.16
scoreerrors_02.txt (14.5 kB)
more ▼

asked May 29 '17 at 02:38 PM in Bug Reports

avatar image

28 2 4 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Of course, this will happen with floating point numbers. Floats are only guaranteed accuracy up to 7 significant decimals. And, since you are in the 50,000,000 and 10,000,000 respectively, you have already taken up more than 7 significant decimal digits. Thus, accuracy is lost when adding, multiplying and etc.

See this stackoverflow for more details on this subject. https://stackoverflow.com/questions/28045787/how-many-decimal-places-does-the-primitive-float-and-double-support

You might consider switching to integer for storing the absolute score value as int64 (long) can store up to 9,223,372,036,854,775,807 on 64bit machines. Then apply your multiplier to a slightly lower number and add that to the absolute integer value. A 32 bit int can store up to 2,147,483,647.

more ▼

answered May 29 '17 at 07:22 PM

avatar image

41 2 5 6

avatar image Jules86 May 29 '17 at 08:11 PM

Thanks Metricton, I appreciate the help.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question