Floating point subtraction rounding error (NOT display error)

Aahz aahz at pythoncraft.com
Thu Dec 13 17:39:19 EST 2007


In article <93a9ea9a-00ab-4022-a567-8ba268790681 at s12g2000prg.googlegroups.com>,
Keflavich  <keflavich at gmail.com> wrote:
>
>Hey, I have a bit of code that died on a domain error when doing an
>arcsin, and apparently it's because floating point subtraction is
>having problems.  I know about the impossibility of storing floating
>point numbers precisely, but I was under the impression that the
>standard used for that last digit would prevent subtraction errors
>from compounding.
>
>Is there a simple solution to this problem, or do I need to run some
>sort of check at every subtraction to make sure that my float does not
>deviate?  I'm not sure I know even how to do that.

Switch to Decimal module?  Available in 2.4 and later.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Typing is cheap.  Thinking is expensive."  --Roy Smith



More information about the Python-list mailing list