[1.0.0] Huge negative number outputs a positive

Bugs that are actually features.
Mr Snrub
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun Oct 11, 2020 11:21 am
Contact:

[1.0.0] Huge negative number outputs a positive

Post by Mr Snrub »

I'm not sure if this is a bug but I thought I'd report anyway and let you guys decide.

What did you do? I have an outpost smelting facility (copper plate) that I have wired with green wire to provide its total (48 iron chest contents that is part of a train station) to another smelting facility/train station that is much closer to the centre of my base. As the second train station is near a high-traffic area I wanted to switch it on only when the first station is low of copper plates (<50k).

Now, I have complicated things by having all stations only turn on when their own contents are >50k. To overcome the original train station setup (turn on when copper plates >50k) I have setup a decider combinator to output the input signal if it is ?50k then a arithmetic combinator to multiply the input signal by -1000000 to try and induce a negative count into the train station to simulate the station not having a count of >50k thus making the station turn off. The problem is that the arithmetic combinator is outputting positive signals for some reason, but only at some points during the count. As you can see in the pictures below at 54k input it is putting out 938k output instead of -946k.

Image
Image
Image
Image

What happened? Due to the arithmetic combinator not outputting as expected it sends a false positive signal and turns my station on.
What did you expect to happen instead? It might be obvious to you, but do it anyway! As soon as the >50k threshold is met the output of the arithmetic combinator makes it into a massive negative number to send to the train station
Write down the steps to reproduce the bug if you know them. Set the combinators as shown in the pictures, wait until the >50k threshold is met and observe the various signals outputted
Does it happen always, once, or sometimes? Always, but at different numbers, for example, 50k didn't output negative, ~52k was negative the 54k wasn't. Once the outpost station is full (a total of around 308,000 copper plates) it always outputs a positive

Be precise! When i click with the mouse on Quit in the main menu... Not: When I close the game. Let me know if the above isn't precise enough. I have attached a save (I have positioned the Spidertron over the arithmetic combinators in question - the outpost of copper plates is to the far right/east of my base. The iron plates outpost in the same location has the same setup and same issue. Its connected station is slightly north on the opposite side of the tracks from the starting point of the Spidertron). There is also a log file attached for you to look at
Attachments
factorio-current.log
(10.26 KiB) Downloaded 78 times
No Belt Space Bus.zip
(39.21 MiB) Downloaded 73 times
kovarex
Factorio Staff
Factorio Staff
Posts: 8298
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [1.0.0] Huge negative number outputs a positive

Post by kovarex »

This is not really a bug.
The circuit system uses signed 32 bit integeres, so the limits follows, once the maximum positive number is 2 147 483 647 (which also happens to be a prime number, I had no idea https://en.wikipedia.org/wiki/2,147,483,647), similar limit is for negative numbers.
User avatar
valneq
Smart Inserter
Smart Inserter
Posts: 1268
Joined: Fri Jul 12, 2019 7:43 am
Contact:

Re: [1.0.0] Huge negative number outputs a positive

Post by valneq »

Welcome to the world of programming! What you experienced first hand is known as an "integer overflow":
https://en.wikipedia.org/wiki/Integer_overflow
Mr Snrub
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun Oct 11, 2020 11:21 am
Contact:

Re: [1.0.0] Huge negative number outputs a positive

Post by Mr Snrub »

kovarex wrote: Sun Oct 11, 2020 12:20 pm This is not really a bug.
The circuit system uses signed 32 bit integeres, so the limits follows, once the maximum positive number is 2 147 483 647 (which also happens to be a prime number, I had no idea https://en.wikipedia.org/wiki/2,147,483,647), similar limit is for negative numbers.

Thought that may have been the case. Thanks for having a look anyway
Post Reply

Return to “Not a bug”