Course Webpage

Exercise

For precision 5, truncate and round to the closest even the following numbers:

\begin{array}{|l|cccccc|} \hline \mathrm{base}\;10 & 1.999956 & 1.999943 & 2.462150 & 2.462250 & 2.462151 & 2.462149\\ \mathrm{base}\;2 & 1.111111 & 1.111101 & 1.010110 & 1.010010 & 1.010011& 1.010001\\ \hline \end{array}

Introduction

Often, for a real number $x$, there is no exact floating-point representation and it falls between two numbers that can be represented exactly $$x^- \lt x \lt x^+$$

As a representation of $x$ we will choose one of the two depending on the rounding method used. The IEEE 754 standard proposes 5 rounding systems.

  • Round Toward Positive: it rounds to the nearest larger number.
  • Round Toward Negative: it rounds to the nearest smaller number.
  • Round Toward Zero: ("truncation").
  • Round Ties To Away: it rounds towards the closest, and if the distance is the same, towards the greatest (in absolute value) closest number.
  • Round Ties To Even: it rounds towards the closest, and if the distance is the same, towards the one with the last digit (the least significant) even.

This is the most widely used rounding method and the one that we will use in this exercise.


Exercise

For precision 5, truncate and round to the closest even the following numbers:

\begin{array}{|l|cccccc|} \hline \mathrm{base}\;10 & 1.999956 & 1.999943 & 2.462150 & 2.462250 & 2.462151 & 2.462149\\ \mathrm{base}\;2 & 1.111111 & 1.111101 & 1.010110 & 1.010010 & 1.010011& 1.010001\\ \hline \end{array}

Base 10

1.999956

  • Truncation: We remove the last two digits to leave 5 digits $\fbox{1.9999}$
  • Rounding: We take the next number in this precision which is 2.0000. The middle point between these two points is 1.99995. Since the number we want to round is greater than this midpoint, it is closer to 2.0000 and rounds up, to $\fbox{2.0000}$

1.999943

  • Truncation: We remove the last two digits to leave 5 digits $\fbox{1.9999}$
  • Rounding: We take the next number in this precision which is 2.0000. The middle point between these two points is 1.99995. Since the number we want to round is smaller than this midpoint, it is closer to 1.9999 and rounds down, to $\fbox{1.9999}$

2.462150

  • Truncation: We remove the last two digits to leave 5 digits $\fbox{2.4621}$
  • Rounding: We take the next number in this precision which is 2.4622. The middle point between these two points is 2.46215. Since the number we want to round is this midpoint, it is at the same distance from the two and it rounds towards the one that ends up in an even digit $\fbox{2.4622}$

2.462250

  • Truncation: We remove the last two digits to leave 5 digits $\fbox{2.4622}$
  • Rounding: We take the next number in this precision which is 2.4623. The middle point between these two points is 2.46225. Since the number we want to round is this midpoint, it is at the same distance from the two and it rounds towards the one that ends up in an even digit $\fbox{2.4622}$

2.462151

  • Truncation: We remove the last two digits to leave 5 digits $\fbox{2.4621}$
  • Rounding: We take the next number in this precision which is 2.4622. The middle point between these two points is 2.46215. Since the number we want to round is greater than this midpoint, it rounds up, towards $\fbox{2.4622}$

2.62149

  • Truncation: We remove the last two digits to leave 5 digits $\fbox{2.4621}$
  • Rounding: We take the next number in this precision which is 2.4622. The middle point between these two points is 2.46215. Since the number we want to round is smaller than this midpoint, it rounds down, towards $\fbox{2.4621}$

Base 2

1.111111

  • Truncation: We remove the last two digits to leave 5 digits $\fbox{1.1111}$
  • Rounding: We take the next number in this precision which is 10.000. The middle point between these two points is 1.11111. Since the number we want to round is greater than this midpoint, it rounds up, towards $\fbox{10.000}$

1.111101

  • Truncation: We remove the last two digits to leave 5 digits $\fbox{1.1111}$
  • Rounding: We take the next number in this precision which is 10.000. The middle point between these two points is 1.11111. Since the number we want to round is smaller than this midpoint, it rounds down, towards $\fbox{1.1111}$

1.010110

  • Truncation: We remove the last two digits to leave 5 digits $\fbox{1.0101}$
  • Rounding: We take the next number in this precision which is 1.01011. The middle point between these two points is 1.01101. Since the number we want to round is this midpoint, it is at the same distance from the two and it rounds towards the one that ends up in an even digit, that is, zero $\fbox{1.0110}$

1.010010

  • Truncation: We remove the last two digits to leave 5 digits $\fbox{1.0100}$
  • Rounding: We take the next number in this precision which is 1.0101. The middle point between these two points is 1.01001. Since the number we want to round is this midpoint, it is at the same distance from the two and it rounds towards the one that ends up in an even digit, that is, zero $\fbox{1.0100}$

1.010011

  • Truncation: We remove the last two digits to leave 5 digits $\fbox{1.0100}$
  • Rounding: We take the next number in this precision which is 1.0101. The middle point between these two points is 1.01001. Since the number we want to round is greater than this midpoint, it rounds up, towards $\fbox{1.0101}$

1.010001

  • Truncation: We remove the last two digits to leave 5 digits $\fbox{1.0100}$
  • Rounding: We take the next number in this precision which is 1.0101. The middle point between these two points is 1.01001. Since the number we want to round is smaller than this midpoint, it rounds down, towards $\fbox{1.0100}$