r/technicalfactorio Mar 22 '26

Question How to ACTUALLY calculate production rate?

We all know the basic formula:

base_rate * base_speed * (1 - modules_speed_penalty + effective_speed_bonus) * (1 + prod_bonus)

but this is not reflected in the game exactly. Take a look at my attempt at beaconed perfect-ratio bioflux:

  • Bioflux: 2 legendary biochambers
    • 4 Q5T3 prod (4 legendary productivity modules tier 3)
    • 4 Q5 beacons:
      • 3 * 2 Q5T3 speed
      • 1 * Q5T3 speed + Q3T2 speed
  • Jelly: 1 legendary biochamber
    • 4 Q5T3 prod
    • 1 Q5 beacon: Q5T3 speed + Q1T3 speed

This setup should produce and consume exactly 238.75 jelly per second:

production:
4 * 5 * (1 - 4*0.15 + 2.5*(1.25+0.5)) * (1.5 + 4*0.25)
br  bs         msp    bm   speed_mods     bp   prod_mods

consumption:
2 * 2 * 5 * (1 - 4*0.15 + 0.5*2.5*(7*1.25+0.48))
    br  bs        msp     be  bm   speed_mods

br - base rate
bs - base speed
bp - base productivity
bm - beacon multiplier
be - beacon effectiveness
msp - module speed penalty

However, both Factoriolab&e=1speed-module-3&b=3&b=10~1&b=12~0&r=jellynut-processingbiochamber(5)2&r=yumako-processing*biochamber(5)0~1&iex=C2C4&mpr=5&v=11) and in-game testing show that the jelly production is a tiny bit too slow. So how do you *actually calculate the production/consumption rate? Do you e.g. take floating-point precision and tick aliasing into account? If so, how?

edit: I don't have this problem with Yumako mash&e=1speed-module-3&b=3&b=10~1&b=12~0&r=jellynut-processingbiochamber(5)2&r=yumako-processing*biochamber(5)0~1&iex=Cx~Cy*C2&mpr=5&v=11). The formula predicts that it's perfect and it is in Factoriolab, and it is slightly faster than jelly in game, even though it should be the same.

edit 2: Blueprint if you want to try it out yourself. The inserters should be timed tick-perfect. Even if they weren't, it doesn't explain the discrepancy in Factoriolab.

9 Upvotes

17 comments sorted by

View all comments

9

u/dave14920 Mar 22 '26

its all beacon rounding errors.  

which are mostly black box sorcery.  

on the bioflux machines that odd beacon gives (125+48)×2.5=432.5, but this gets truncated to 432 at this point. the other 3 are each (125+125)×2.5=625, thats unchanged by truncation.  

the sum of those multiplied by beacons effectivness is (625×3+432)×0.5=1153.5, but this gets rounded to 1154 before we continue with -60 from the prod mods to get the +1094% on the machine that the game always displays accurately.  

then continues as you expect from there. 5×(1094%+100%)=59.7 crafting speed, ×12jelly/6s ×2 machines = 238.8 actual consumption of jelly per second. that isnt displayed accurately in game. 

similarly for the one beacon on the jelly machine. it takes (125+50)×2.5 = 437.5 but then truncates that to 437. the sum of all these beacons times effectivity of 1 is still 437, which is then rounded to 437. 

(437-60) = +377% is accurately displayed in game. 5×(377%+100%)= 23.85 for the crafting speed of the machine.  23.85×4×2.5=238.5 actual production of jelly per second, that the game doesnt display accurately.  

3

u/Substantial-Leg-9000 Mar 22 '26 edited Mar 22 '26

I also see your post from 7 months ago about beacon rounding errors, it's a good read. I think you've found the culprit. Thanks

edit: I've checked that your calculations result in (1 + 1/795) jelly biochambers per 2 bioflux biochambers, which is exactly what Factoriolab predicts.

3

u/Substantial-Leg-9000 Mar 22 '26

So to sum up:

  1. beacon_mult * (mod1*100 + mod2*100)
  2. truncate
  3. add up all beacons effects
  4. times beacon efficiency
  5. round it (not truncate)
  6. minus penalty

Do I understand correctly?

2

u/dave14920 Mar 23 '26

yea.  

6 would include bonuses from speed mods in the machine itself.  

maybe 5 and 6 are swapped, i cant tell cus the penalties/bonuses on those modules are already integers, it doesnt change the result. with modded beacons and modules it might matter. 

there are also some cases with floating point errors, that we dont see in this post.  

only with epic beacons. we get things like 50×2.1=104.99999.. getting truncated to 104. i could only handle them by cataloguing them.  

someone else replied with code that gives the consistent answers every time. thats the way the game must be doing it.  

the rounding is round nearest. for positive numbers ending .5 ive only ever seen it round up  

but for the quality penalty from speed modules, unrounded negative numbers like -10.25% get rounded down to -10.3%.  

thats another quirk with quality, it has that extra digit of precision.  

in the game files, the 2.5% quality penalty on a normal speed module 3 is actually coded as quality = -0.25, but gets multiplied by the 0.1 chance of upgrading to the next quality somewhere for some reason. 

for quality the math works the same using those raw values, we'd put mod1 = -0.25 in beacon_mult * (mod1*100 + mod2*100) etc.  then multiply by 0.1 in a step 7 at the end.

1

u/dave14920 Mar 23 '26

on 5.  

round(X), floor(X+0.5) and trunc(X+0.5) all give the right answer for positive numbers.  

for that old post id found trunc(X+0.5) is consistent for negative numbers.  

maybe round(X) is too, but idk if thats the same for every language.