GRG writes: I've been trying to track down an error in a certain program, used by hundreds of people around the world every day to process gigabytes of very important data. Sometimes it works "fine", other times, not often, only about 0.41% off the time, it goofs up the data, from minor-league (0.22%) to big-time (80%). Apparently the users of this data are not very careful, as the program has had these bugs for at least six years.

It took quite a few days to track down the problem, as the program, for no good reason, resides in about 188 separate FORTRAN and C source files. Finally I found the source of the glitch. Let's see if you can spot the problem too.

Now let's say you have a number, say 2022, and you'd like to calculate what power of two it is. More exactly, you'd like to figure out how many bits you'd need of a binary integer to represent it. And in addition you'd like the answer to be exactly reversible -- i.e. if you turn the crank backwards, you'd like "2048" to come out.

Here's the code in the program, the part that figures out the number of bits. By the way, it exists in this exact form in exactly 54 separate places in the source code. There are at least TWELVE things wrong that I can see, just in the last line:

   real range;   integer max, min,nbits;
   min = someinteger;  max = someotherinteger;
   range = abs( max - min );
   nbits = int( alog( real( range + 1 ) ) / alog( 2 ) )

See the first comment for the twelve problems that GRG identified ...
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!