[1.1.76] [minor] Recipe result probabilities not rounded consistently on tooltip

This subforum contains all the issues which we already resolved.
Post Reply
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

[1.1.76] [minor] Recipe result probabilities not rounded consistently on tooltip

Post by Deadlock989 »

ItemProductPrototype, the prototype for a result in a recipe which returns multiple results, has a probability property (type double) which represents the chance of the recipe's completion actually returning the result. This is expressed as a number between 0 and 1, so a 58% chance is represented by 0.58.

In the case of integer percentages (represented by steps of 0.01 from 0 to 1) there seem to be some numbers that do not enjoy being stored in a table: when retrieved, they are approximated. If you run the following during a mod's data stage:

Code: Select all

log(0.58)
log(serpent.line({probability = 0.58}))
you will get something like this:

Code: Select all

   1.060 Script @__xxxx.lua:4: 0.58
   1.060 Script @__xxxx.lua:5: {probability = 0.57999999999999998}
Some numbers are minutely under (e.g. 0.18 is represented as 0.17999999999999998) while others are minutely over (e.g. 0.14 is represented as 0.14000000000000002, 0.46 is represented as 0.46000000000000005). Others escape unscathed. I assume this is some kind of floating point representation issue.

For gameplay, this difference in probability doesn't matter in the slightest.

What is odd (and has been reported to me as if it were a bug in my mod) is that recipe tooltips round these values up very sensibly for every case except 0.58 - the mod in question has an array of recipes from 2% to 98% in 2% increments (probabilities of 0.02 to 0.98). All of the tooltips are nicely rounded with the exception of 58% (specified as 0.58, represented in the table as 0.57999999999999998), which is shown as 57.99% (see below). The recipes concerned also have a pollution modifier, in this case also specified as 0.58, which is shown correctly as 58%. Numerous other values which are minutely under (0.nn999999999999998) are also shown correctly. I don't know what is special about 58%.

Untitled.jpg
Untitled.jpg (119.3 KiB) Viewed 1325 times
Image

Genhis
Factorio Staff
Factorio Staff
Posts: 120
Joined: Wed Dec 24, 2014 8:19 am
Contact:

Re: [1.1.76] [minor] Recipe result probabilities not rounded consistently on tooltip

Post by Genhis »

Thanks, the issue is fixed for the next release.

Post Reply

Return to “Resolved Problems and Bugs”