Yesterday at work, like any friday when i plan to leave early, came the dreaded last-minute to-be-fixed-urgently bug in the program, forcing me to delve further into some 20-year-old Fortran mess. Let's not mention the hour spent trying to make sense of the useless email conversation with sometimes contradictory statements from people having mostly no idea what was going on, together with the "Fix it!" tag; it turned out that the Fortran code was supposed to read some (real) numbers from an input file, and that action had started to fail as those numbers where getting bigger. In the end, my colleague in charge of the other program writing the input the Fortran code was coughing up on fixed it in the input itself, just by adding a comma at the end of the big numbers, as we had determined everything was fine in that case.
Still, it took me a while to figure out what had been happening, since any other (smaller) number produced no problem whatsoever, even without comma. One last test made it clear: The offender was something around 2.2 billions, and everything was fine up to 2.1 billions... Or more exactly up to 2147483647, since that is (2^8)^4/2-1, i.e. the maximum value that's possible to store in a (signed) 4-byte integer. There was then somewhere a cast to make it a float for the rest of the program, and thus things started to get ugly above that limit.
In the end, if you ever write a program with a counter for the total population on the Earth, you'd better use a real variable or make sure your integer is really an integer*8...
Saturday, September 19, 2009
Subscribe to:
Posts (Atom)