# How does the machine round in floating point arithmetic?

What is the convention for rounding operations in floating-point arithmetic?

Let's suppose we are using 64 bit precision and want to sum the numbers $1$ and $2^{-53}$ in floating point arithmetic. That is, we want to perform the following operation:

$1 + 2^{-53}$

We consider their representation:

$$1 \ \ \ \ \ = 2^0 \ \ \ \ \times 1. \underbrace{0000 \dots 0000}_\text{52 digits}$$

$$2^{-53}=2^{-53} \times 1.\underbrace{0000 \dots 0000}_\text{52 digits}$$

Then a shift is performed in order to sum, so we sum like:

$$2^0 \times 1. \underbrace{0000 \dots 0000}_\text{52 digits}$$

$$+ \ \ \ 2^{0} \times 0.\underbrace{0000 \dots 0000}_\text{52 digits}1 \ \ \ \$$

Now the result is $$2^{0} \times 1.\underbrace{0000 \dots 00001}_\text{53 digits}$$ so a rounding must be performed. Both rounding up and rounding down produces the same rounding error, so what is actually done? I have tried this with Matlab and it rounds down to $2^{0} \times 1.\underbrace{0000 \dots 0000}_\text{52 digits}$.

How can I know how the machine rounds the number in any situation?

• It's described on Wikipedia pretty well: en.wikipedia.org/wiki/Floating_point?wprov=sfsi1 – user251257 Nov 17 '16 at 12:05
• I don't remember some of the specifics, but if I remember correctly, the operation is initially carried out in a way which returns more digits than will actually be returned, and then afterward it is rounded using a rounding rule. Knowing those additional bits allows you to apply "round to nearest, ties to even", which is the default rounding method. en.wikipedia.org/wiki/IEEE_floating_point#Rounding_rules – Ian Nov 17 '16 at 12:05
• So $1+2^{-53}$ first looks like $1$, $52$ significant zeros, and then an insignificant $1$ (if I recall the exact memory layout correctly). Thus there is a tie between rounding it to $1+2^{-52}$ and rounding it to $1$ (each commits a rounding error of $2^{-53}$). Round to even decides to round it to $1$ specifically. – Ian Nov 17 '16 at 12:11