Fixed precision floating point arithmetics in Factorio using circuits
no mods required -# Factorio Floating Points![FFP] (not 1 to 1 identical to floating points but same idea)
why?
Factorio circuit netowrks can only use 32-bit signed integers, meaning there are no decimals! Usually that doesnt matter, but in my "tempomat"(aka space platfrom speed controller) i actually got hindered by that limitation and had to use a vague aproximation instead of the derived formula. that annoyed me. so i made this. This "FFP standart" allows you to do any calculation comparatively very precisely. -# im going to be the only using it pobably lol
how it works
main formula: value=(2^(mantissa) * fraction)/(2^P) -# negative mantissas/exponents here work aswell for internal calculations btw, just make sure to cleanup before converting to INT again
this fraction value is baisacly the same as other standards but multiplied with 2^P P here is the precision value (in the Combinator in factorio you dont enter P, you have to enter 2^P) P in the combinator is the "Dot Signal"
when increasing P, you increase precision, but lose max value for the conversions. when decreasing P, you decrease precision, but gain max value for the conversions. most rounding errors happen when converting back to INT, i recommend a P value between 5 and 15 (i use 10).
limits
Internally (so when calculating using "my" FFP standart) the theoretical max value is 2^(2^31 -1) *2, but you cant translate that into an INT again. Max input value is always limited to 2^(31-P) Max output is limited to 2^31 when using the non "simpl" version of conversion -# i couldn't yet figure out how to do the same for input but its fine ig.
any
all cuitcuits are avalable as a "any" vairant. I recommend using those because using the single variants it will make your circuits just HUGE. what is in INT one combinator can now be 5-22 size wise. the any variants have the mantissa on green and the fraction on red instead of single wire 2 signals. this makes things significantly more compact.
sometimes after calculations you may get some wierd looking values (that should still work tho! aslong as they're not above 2^31 or fraction<1), so there is a cleanup circuit aswell which makes them look prettier again. for the rest the descriptions in the blueprint should make this self explanatory.
I put input usually always at the top and output at the bottom power poles.
