George Carter
Home | Blog | All Tags | Now | Search

The Biggest Bug That Took 43 Years To Spot

| Friday 10th November, 2023

I was having some fun coding on a ZX Spectrum emulator today and a strange bug appeared.

Playing with it, I’ve taken it down to its simplest form with the following code:

10 PRINT 1/2=0.5
20 PRINT 0.5=1/2

The spectrum returns 1 for TRUE and 0 for FALSE.

Given the code above, what is the output? You’re expecting:



Unfortunately not. The emulator returns:


So 1/2 doesn’t equal 0.5, but 0.5 does equal 1/2.

I know there are issues with precision on old 8-bit machines, but really? It can’t be this bad? Taking into account floating point arithmetic, 1/2 is incredibly easy to represent (2 to the power of -1).

Where does it all go wrong? Where’s the rounding error? Does this happen on the real machine?

If it does happen on a real machine, how come I haven’t become aware of such a simple bug in the last 41 years that the humble speccy has existed?

If you have a real spectrum, please try it out and leave a comment with the results…


← ZX Basic Decimal To Fractions | Why I Love The Small Web →

Leave a Reply

Your email address will not be published. Required fields are marked *

Happy to discuss anything you read here by email: