# How does a computer interpret real numbers?

I understand that the modern day digital computer works on the binary number system. I can also get, that the binary representation can be converted to rational numbers.

But I want to know how does the present day computational model interpret real numbers.

For eg:

On a daily basis we can see that a computer can plot graphs. But here, graphs may be continuous entities. What is the mathematical basis, that transforms a discrete (or countable, at most) like the binary system to something mathematically continuous like a say, the graph of $$f(x) = x$$.

• Possible duplicate of this Wikipedia article: en.wikipedia.org/wiki/Floating-point_arithmetic – John Dvorak Mar 22 '19 at 15:38
• Aside from floating-point approximations, there are systems that deal with the reals as mathematical entities, most notably computer algebra systems and theorem provers. Representing a particular real number "directly" (for a certain interpretation of "directly") is restricted to the computable numbers. – Jeroen Mostert Mar 22 '19 at 15:54
• IEEE 754 is the answer. – Jasper Mar 22 '19 at 16:13
• I'm not sure exactly what you're trying to ask. It's OK that you didn't put a check mark beside either of the answers but since you didn't write the question clearly and you didn't get an answer that solved your problem and show that it solved your problem, I'm not sure what's you're trying to ask. Do you mean something like "How does a computer write a formal proof in ZF of a statement about all real numbers when some real numbers it cannot possibly store enough information to completely describe? If a computer is a physical device that follows simple laws, how can it be like the human brain – Timothy Mar 23 '19 at 0:29
• which can do creative thinking and start new mathematical research? The human brain can think of the statement that all statements provable in the formal system of Peano arithmetic are true and think of a proof of it but the formal system of Peano arithmetic itself cannot even describe that statement let alone prove it. Could the explanation be that although the human brain follows simple laws and when a human says that statement is obviously true, it is really just the result of the brain following those laws and making you say that sentence, that sentence actually represents a real statement – Timothy Mar 23 '19 at 0:36

They represent continuous quantities with discrete approximations. Mostly, this is done with floating point, which is analogous to scientific notation. Essentially, they work with something like $$1.xyz\times 10^k$$, with some appropriate number of decimal places (and in binary, rather than decimal).

It's also possible to work with some irrational numbers directly. For example, you could create yourself an object called "$$\sqrt{2}$$" without particularly worrying about what it is, except that it obeys the usual arithmetic rules and that $$(\sqrt{2})^2=2$$. So then you could compute $$(\sqrt{2}-1)(\sqrt{2}+1) = (\sqrt{2})^2 + \sqrt{2} - \sqrt{2} - 1 = 2 - 1 = 1$$ exactly, as an algebraic fact that's not susceptible to rounding errors.

Note that, if you're plotting a graph on screen, regardless of how far you zoom in, you're plotting it as discrete pixels so using an appropriate number of significant figures basically gets you everything you need.

• +1. For folks interested in more information about your second paragraph, some good search terms are symbolic computation and computer algebra. – ruakh Mar 22 '19 at 22:57

The real numbers are uncountable. The set of real numbers that can be represented in any way is countable. Therefore, almost all real numbers cannot be represented by a computer at all.

The most common method is to store floating point numbers, which are reasonably precise approximations to real numbers that are not excessively large or small.

• In fact, infinitely many real numbers can't be represented. It's just a slightly smaller infinity than the infinite number of all real numbers. :) – Graham Mar 22 '19 at 23:50
• @Graham: It's actually the same infinite cardinality. gnasher729 is using "almost all" in a precise sense; see en.wikipedia.org/wiki/Almost_all for details. – ruakh Mar 23 '19 at 0:11