in reply to perl subtraction

61/100, 33/100 and 94/100 are all periodic numbers in binary (like 1/3 is in decimal). It would take infinite storage to represent them accurately as floats. You're noticing errors from the inability to store the numbers accurately.
_____ 61/100 = 1.3851EB * 2**(-1) _____ 33/100 = 1.51EB8 * 2**(-2) _____ 94/100 = 1.E147A * 2**(-1)
(Using hex for the mantisa)

Replies are listed 'Best First'.
Re^2: perl subtraction
by jagdish.eashwar (Novice) on Jan 10, 2010 at 09:24 UTC
    Hi,

    But
    perl -e "print 100.61 + 100.33 - 200.94"
    works correctly.
      Sometimes the errors cancel out. Floats also do a bit of rounding for you to try to avoid problems. You need to do some of your own.