Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Possible floating point error?
#3
(@Jack beat me to it and said it more concisely.)

Steve has mentioned in previous posts how some numbers cannot be represented exactly in binary floating point, and that seems to be the case here.

That tiny error is not a bug, it's just because of the difference between our expectations and the way floats are represented internally.

That's why financial institutions prefer decimal math to binary.  If every $100 transfer is recorded as $99.99999, then those bank execs are going to have headaches.

In everyday use little errors like that can either cancel out over time or add up to something more noticeable.

(I seem to recall that in olden time some MS Basics would ever so slightly round floats before printing them to hide those ugly inaccuracies.)


Interesting.
f = 2 / 454
x = 227 * f
yields .9999999

while
x = (2 / 454) * 227
yields 1.
Reply


Messages In This Thread
Possible floating point error? - by TerryRitchie - 05-30-2024, 01:02 AM
RE: Possible floating point error? - by Jack - 05-30-2024, 01:34 AM
RE: Possible floating point error? - by JRace - 05-30-2024, 01:48 AM
RE: Possible floating point error? - by SMcNeill - 05-30-2024, 02:30 AM
RE: Possible floating point error? - by SMcNeill - 05-30-2024, 03:31 AM



Users browsing this thread: 7 Guest(s)