So Computers Actually Guess A Lot More Than You Think They Do

Decimals aren't real. Computers pretend to know the answers to calculations before they're done. It's kinda crazy out here.


Note to all the electrical, computer, and other hardware engineers: hardware is not my strong suit. This will be a gross oversimplification of how this works. Please don't hate me.

Computers Aren't Doing What You Think They're Doing

So when you were learning about computers, you were probably told that they make very specific, very exact calculations very quickly. If you weren't told that, this is the general consensus for how to talk about computers so I'm going to need you to just trust me on this one for a little bit.

Moment's over—that's a lie. Computers actually make a ton of guesses while they're running calculations in a lot of different places. We're going to talk about a few of them.

Tech Term: Floating Point Integers - Decimals

Computers Don't Technically Understand Decimals

With computers you're dealing with binary—1 and 0—to express the entire universe that is a computer. Now, that maps to whole numbers rather well, 0 is '0', 1 is '1', 2 is '10', 3 is '11'.

But what's π? Well we know 3 in binary is '11' and 4 is '100' so where does 3.14159...go? For all intents and purposes, the computer makes an approximation when it comes to floating point integers (decimals) and it...well it tries its best. This is why, in some programming languages, you can try and ask it if 0.1 + 0.2 = 0.3 and it says no. If you ask it what 0.1 + 0.2 is, it'll probably say something like 0.300000000004 . Which is, decidedly, not 0.3 . There are ways for programmers to work around this, but all you really need to know is that it's a problem that exists with computers.

Because they literally don't know what a decimal is.

Tech Term: Branch Prediction - This is a process where a processor will, quite literally, attempt to predict what the answer to a calculation will be

Another Part of the Computer That Guesses

A lot of the increases in processor speed over the past few decades have been through perfecting a process called "Branch Prediction". If you imagine a fork in the road where you need to make a choice, these are your branches. The computer will literally guess which path to go down using "its best judgement" (a bunch of complicated math stuff we're not going to talk about because, quite honestly, it scares me to think about).

What this means is that, if the processor is waiting on a long calculation, it can do a branch prediction and keep working with its best guess of what the answer is. If it finds out that it's wrong when the original computation finally completes, it throws all of that work out and starts again with the right number. If it did come up with the right number, then it just saved all that time not waiting around, getting you to your memes just that much faster.

So, now you're probably thinking "well if it did all of that work that ended up being a waste of time, then how is this faster?"

Well, the answer is, quite frankly, kinda stupid: yes, if it's wrong, then the processor did a whole bunch of unnecessary math. The solution? We just make it better at doing the branch prediction. If it's right enough of the time, then we end up saving time, so a lot of engineers work together to improve this prediction process as much as possible.

So There You Have It

Yeah. Computers guess a lot more than you think they do. Our solution? Trying to make them better at guessing. Yup. That's really how it works.



1