RFTools

RFTools

74M Downloads

Improve Spawner Floating Point Math

tommyTT opened this issue ยท 4 comments

commented

I have encountered the following problem when using the RFTools spawner block in my wither farm: a nether star gives 1.5 of the key matter (fully infused beamers) and with the default configuration it requires 0.1 to spawn one wither, which is a pretty good deal. Let's assume I give it more than enough of the other materials, in total I would expect to be able to spawn 15 withers but in reality it gets stuck after 14 spawns. Looking into the spawner GUI itself it still shows 0.1 of the key matter available, but it won't spawn. I then used the machine module in a screen and there it shows the real number of matter which is just below 0.1 (0.09999981). The reason of course is the floating point variables that are used as demonstrated by the following piece of java code:
Float asFloat = 0.1f; System.out.println(asFloat); float val = 1.5f; while (val > 0.0f) { System.out.println(val); val -= asFloat; }

The output is:

0.1
1.5
1.4
1.3
1.1999999
1.0999999
0.9999999
0.89999986
0.79999983
0.6999998
0.5999998
0.4999998
0.3999998
0.2999998
0.19999981
0.09999981

This shows, that after the second spawn the precision gets messed up and all automation around the spawner gets also out of sync.
It would be helpful if the values get rounded somehow or another data type is used that can better represent these numbers (preferably scaling everything to integers?).

commented

This will be hard to fix really. Especially when infused the amounts are not really easy to round. And no matter what type of rounding is done, there will always be a case where this fails. What I do in general to prevent automation going wrong is to just add an extra item (like one extra wither star) so that there is always enough

commented

That is currently my solution too, the tricky part however remains the GUI of the spawner. There you can't see the real number, only a rounded value that would be enough for the next spawn, so at first I had no idea of what is actually happening. Maybe you have an idea on how to improve that, so others won't run into the same issue?

commented

Yes, in the GUI I can probably fix it so that it doesn't show a rounded up version

commented

Fixed next release by disabling rounding for the display