in reply to 4253.95 + 0.9 = 4254.84999999999 (need help to interpret internals)

It has already been said, but it bears repeating since so many people get caught out. There is no such thing as floating point with "reasonably uncomplicated values". Just because a number looks sane in base 10 doesn't mean it's a rational number in binary.

You have a few choices about how to deal with this issue. It does depend on how important this is to you, and what you are trying to accomplish. People writing software for financial institutions will do different things from students just playing with lab results.


Update: Hi ikegami, I meant "rational" loosely as a synonym for sane just to avoid repeating myself. I shouldn't have used a word with a well-known mathematical meaning. :-)
  • Comment on Re: 4253.95 + 0.9 = 4254.84999999999 (need help to interpret internals)

Replies are listed 'Best First'.
Re^2: 4253.95 + 0.9 = 4254.84999999999 (need help to interpret internals)
by ikegami (Patriarch) on Feb 25, 2005 at 16:25 UTC
    Just because a number looks sane in base 10 doesn't mean it's a rational number in binary.

    Rationality is independant of base. A rational number in base 10 will still be rational in base 2. You mean not periodic. A number which isn't periodic in base 10 may be periodic in base 2, but periodic numbers are rational.