in reply to Floating Point Errors

Don't use floating point math. Start with integers. Never overflow, never divide, and everything will be fine.

You might be interested in What Every Computer Scientist Should Know About Floating-Point Arithmetic.

Replies are listed 'Best First'.
Re^2: Floating Point Errors
by Anonymous Monk on May 27, 2008 at 21:05 UTC
    well I need to use floating integers because my precision should be at about 0.01. The project is about molecular modelling so I am using perl:pdl and there are many times I need to take inverses of operators. It is highly unlikely that I can avoid floating integers :/ I was just right now reading the article you gave though, thanks.

      I think what kyle was trying to say is that you will always have errors with floating-point. The only way to avoid them is to rescale all your operations to used fixed- point math. It can be done. Before system designers had math co-processor chips and Pentium uber-chips many analog systems were designed using fixed point math.


      s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}

      starbolin is correct. I struggled through a whole semester about nothing but floating point problems, and almost the only thing I took away from it was, "don't use floating point numbers."

      There are an infinite number of real numbers between 0 and 1, but only a finite number of them can be represented the way floats are normally stored. Out between 100 and 101, there is the same infinity of real numbers, but even fewer of them can be represented.

      Looking at the number line through the filter of a float is a sea of emptiness and disappointment, I tell you!