Take the 2-minute tour ×
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It's 100% free, no registration required.

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?

share|improve this question
2  
You may be interested to read en.wikipedia.org/wiki/Round-off_error –  Mok-Kong Shen Jan 26 '13 at 21:22
add comment

2 Answers 2

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.

share|improve this answer
add comment

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

@InCollection{Knuth:1990:SPW:119872.119899,
  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},
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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