I have been posed with a question whereby a computer truncates numbers to x number of digits. Due to this, if this computer is trying to store a decimal number which has a binary equivalent greater than x, it truncates the remaining digits producing a different binary number. However, this binary number is still an 'approximation' of what it should be, but of course is the equivalent of a different decimal number (close to what we were trying to store initially).

What problems can occur due to this incorrect storage of data?


This is specifically about real numbers — integers can be represented exactly. Actually, real numbers can be represented exactly too, at least the one that matter, but this is very inefficient, so for most applications real numbers are represented by a floating point approximation.

By the way, this isn't specific to decimal numbers (numbers that can be represented in base 10 with a finite number of digits after the decimal point). No matter what base you choose, you can only represent a tiny subset of the real numbers (you can't even represent all rationals).

When computing with approximations, it's important to keep in mind that each step of computation may make the approximation worse, so that after many steps it's not always obvious how precise the result is — in some cases, the result is meaningless because the magnitude of the uncertainty is larger than the result. Numerical algorithms need to be constructed carefully to minimize errors due to approximations.

There is a whole subfield of computer science devoted to floating point calculations. To start with, read the classic paper What Every Computer Scientist Should Know About Floating-Point Arithmetic by David Goldberg.

| cite | improve this answer | |

The question of finding a binary fraction which can be transformed back to the same decimal fraction was analized at great length by Knuth in his "A Simple Program Whose Proof Isn't", see

  language =     {english},
  author =       {Knuth, Donald E.},
  title =        {A Simple Program Whose Proof Isn't},
  booktitle =    {Beauty is Our Business},
  editor =       {Gries, David},
  year =         {1990},
  isbn =         {0-387-97299-4},
  pages =        {233--242},
  numpages =     {10},
  url =          {http://dl.acm.org/citation.cfm?id=119872.119899},
  acmid =        {119899},
  publisher =    {Springer-Verlag New York, Inc.},
  address =      {New York, NY, USA},
| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.