Floating point subtraction rounding error (NOT display error)

Keflavich keflavich at gmail.com
Thu Dec 13 18:20:14 EST 2007


Solved: used round(number,12) in this case for all of the operands of
my arcsines.  Not pretty, but at least VIM made it easy...

Thanks for the help,
Adam


On Dec 13, 4:01 pm, Keflavich <keflav... at gmail.com> wrote:
> The decimal package isn't what I'm looking for - I don't want to have
> to retype every variable in my code, and I have arcsines showing up on
> about a dozen lines right now.  It also seems like a rather
> complicated way to deal with the problem; maybe I just need to
> implement my own rounding code, but I figured something of that sort
> must already exist.
>
> Thanks though,
> Adam
>
> On Dec 13, 3:50 pm, Keflavich <keflav... at gmail.com> wrote:
>
> > Thanks, I'll have a look at that.  I'm not sure the decimal type is
> > included in numpy, though, which is what I'm using.  It doesn't show
> > up in their documentation, at least.
>
> > Adam
>
> > On Dec 13, 3:39 pm, a... at pythoncraft.com (Aahz) wrote:
>
> > > In article <93a9ea9a-00ab-4022-a567-8ba268790... at s12g2000prg.googlegroups.com>,
>
> > > Keflavich  <keflav... 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 (a... at pythoncraft.com)           <*>        http://www.pythoncraft.com/
>
> > > "Typing is cheap.  Thinking is expensive."  --Roy Smith




More information about the Python-list mailing list