# The sum of two floating point numbers also a floating point number.

I just starting learning about floating point numbers in my computing class. The professor mentioned something important in a lecture that I wrote down but now I'm not sure if it makes sense or I'm stupid. If we have a floating point number, $$a \in \mathbb{G}$$, then it is not possible to represent it as a natural number, which can lead to some error, relative or absolute depending on which one you're looking for. We also know that $$G(x+y) \neq G(x) + G(y), \ x,y \in \mathbb{G}$$, however if we have two floating point numbers $$\alpha, \beta \in \mathbb{G}$$ then is the sum of these two floating point numbers also a floating point number, i.e. $$\alpha + \beta \in \mathbb{G}$$?

• Yes, since there's an algorithm that is defined on x86 floats to define addition. Nov 3, 2019 at 22:16
• The ordinary sum of two floating point numbers doesn't need to be a representable number. For example, the sum of $1$ and half of the machine epsilon $\epsilon/2$ cannot be represented. The closest representable number to their sum is just $1$. Nov 3, 2019 at 22:21

Assuming $$\mathbb G$$ is the set of values that can be encoded in a particular "floating-point" data type on a particular computer, every number $$a \in \mathbb G$$ is a real number, and conversely every real number $$a$$ that happens to be a member of $$\mathbb G$$ can be represented exactly in that floating-point data type.

But there are only finitely many numbers in $$\mathbb G$$ and there are infinitely many real numbers. There are even infinitely many real numbers between $$0$$ and $$1.$$ So some of those numbers won't be found in $$\mathbb G$$ and cannot be represented exactly in that floating-point data type.

For example, suppose we built a computer where the base of its floating-point type was $$10$$ instead of $$2$$ (which I think has actually been done at one time or another using BCD for the mantissa of a number). And suppose that due to lack of modern chip fabrication methods we decide to have only three digits in the mantissa of these numbers. So $$31.1$$ can be represented exactly, but $$31.21$$ cannot. If we try to put $$31.21$$ into a variable of floating-point type in our computer it gets rounded to $$31.2.$$

Then $$31.21$$ is an example of a perfectly well-defined real number that nevertheless is not found in $$\mathbb G$$, and it's not because the number is too large to represent. It's because of rounding.

Now let's say that as in the second part of your question we have two real numbers $$\alpha$$ and $$\beta$$ that happen to be exactly representable in our computer's floating-point type, that is to say, $$\alpha \in\mathbb G$$ and $$\beta\in\mathbb G$$. Is $$\alpha + \beta \in\mathbb G$$?

The answer is, not necessarily. Suppose, for example, that $$\alpha = 30.2$$ and $$\beta = 1.01.$$ These are both perfectly good real numbers and (as it turns out) both $$\alpha \in\mathbb G$$ and $$\beta\in\mathbb G$$ because each number has only three significant digits. But if we add these two real numbers together, the result is $$\alpha + \beta = 30.2 + 1.01 = 31.21$$. And as we already know, $$31.21$$ has too many significant digits to be represented in our computer's floating-point type. That is, $$\alpha + \beta \not\in \mathbb G$$.

It is true that in most cases when our computer adds two floating-point numbers it will produce another floating-point number as a result. But that's not what we mean when we say for two real numbers $$\alpha$$ and $$\beta$$ that $$\alpha + \beta \in \mathbb G$$. When we say $$\alpha + \beta \in \mathbb G$$ we mean that the exact sum of $$\alpha + \beta$$ is still representable in $$\mathbb G$$. And it isn't always true, because many sums are forced to be rounded off. A rounded-off sum is not exact.

Yes. The sum of two floats will be a float. However, if your resulting float is too large (i.e. larger than 32 bits) then most programming languages will just return "infinity".