Wednesday, May 05, 2021

Once More Unto the Breach

I'm going to make a certain subset of my readership’ eyes widen and their ears perk up: the largest stock price that the NASDAQ stock exchange software can represent is $429,496.7295.

See? I wasn't wrong, was I? Many of you are laughing.

So now we know that the NASDAQ software represents a per share stock price as a 32-bit unsigned integer number in units of one-hundredths of a cent. If we convert the $429,496.7295 into units of one-hundredths of a cent (or ten-thousandths of a dollar), we get 4,294,967,295 (or 0xFFFFFFFF in hexadecimal, for those of you into that sort of thing). That value equals 232-1, which is the largest unsigned integer number you can fit in thirty-two bits. Add just one to this value and you get 4,294,967,296 or 0x100000000, which requires thirty-three bits to represent in binary, too large to fit into thirty-two bits. The result rolls over back to 0, the value in the lower-order thirty-bits.

This is just another example like the Y2K issue, or the UNIX epoch issue, what my embedded colleagues and I have generically referred to as the counter rollover bug. I have encountered this class of bug many times in my career, and written about its occurrence more than once. (See the bibliography below.)

The problem was revealed when the price of one Class A share of Warren Buffet's company Berkshire Hathaway started trading at $421,000. NASDAQ is rushing to complete a software upgrade, hoping to get it tested and installed before the price goes much higher.

This problem affects even those stocks (like Berkshire Hathaway) that are traded on other exchanges. NASDAQ has a stock price quoting service that reports on stocks that they themselves don't trade. In fact (I had to look this up) NASDAQ originally stood for "National Association of Securities Dealers Automated Quotations" and was merely a quotation service.

https://www.forexlive.com/news/!/berkshire-hathaways-stock-price-is-too-high-nasdaq-temporarily-suspended-prices-20210505

Bibliography

C. Overclock, Time Flies, 2015-05-09

C. Overclock, Time Flies Again, 2019-07-27

C. Overclock, 32,768, 2019-11-27

C. Overclock, Meet the new bug, same as the old bug., 2020-04-04

Acknowledgement

Thanks to my old friend and colleague John Meiners for the correction.

No comments: