Monday, June 14, 2010

signed long int Cash_Money

The statistics in the statistics tab are not exactly reliable. Some of the errors they contain are bizarre (deaths in arena categories you've never played in, for example) but some are all too predictable.

It seems that the developers used 32-bit integers to store gold, both in your backpack and on the statistics page. 32-bit integers are pretty big, and record numbers a little over 2 billion, but there are two problems.

First of all, 2 billion is a really big number if you are talking about gold. We are not talking about gold here, however, but rather about copper. The game stores your money as a number of copper and formats it into gold/silver/copper for display only. 2 billion divided by 10,000 is only 200,000. In fact, the number in question is 214,748.3647, the familiar "214k and change" that someone will say if you ask "What's the gold cap" in trade chat.

Now, if you are part of a very small subset of people who has memorized the powers of 2 but is not familiar with computer science, you'll think, "What a minute, 2,147,483,647 is not 2 ^ 32 - 1, it's 2 ^ 31 - 1. Where did that last bit go? It went to keeping track of whether your cash-on-hand is positive or negative. Just in case you have negative cash, I suppose.

When a number can't be negative, you can use an unsigned numerical type to release that extra bit and use it to store more number instead of storing useless information. This is probably rarer practice than it should be. If the developers had done this then the answer to the trade chat question would be "429k and change" and we'd have a lot fewer people at gold cap. This, of course, wouldn't really make much of a difference to anything.

But while your money has an error message to protect it from overflowing its alloted bits, your statistics page has no such protection. If you earn 215,000 gold over your character's career, the statistics tab with faithfully report your lifetime earnings as just under negative 2 billion copper. Having overflowed the 31-bits of money storing memory you've flipped the 32nd bit and moved to negative town. If the developers never thought anyone would collect 214k gold when they were doing the alpha for classic WoW, they can be forgiven for that assumption. If they thought, however, in the Wrath alpha that no one would ever earn more than 214k gold over the entire course of their character's career, that is significantly more bizarre. What is much more likely is that in both cases they simply didn't think about it at all.

1 comment:

  1. It turns out that max cash is 2,147,483,646 not 2,147,483,647. This, I have to assume, is an error caused by the use of a >= when they meant >, but I can't be sure.

    ReplyDelete