Floating point subtraction rounding error (NOT display error)
Keflavich
keflavich at gmail.com
Fri Dec 14 10:56:23 EST 2007
On Dec 14, 8:28 am, Carl Banks <pavlovevide... at gmail.com> wrote:
> On Dec 13, 6:20 pm, Keflavich <keflav... at gmail.com> wrote:
>
> > 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
>
> I suspect this could even fail in some circumstances. If it's for
> school you're probably covered, but in real world, it would be better
> to:
>
> 1. Rewrite calculation to avoid arccos and arcsin (using trigonometric
> or geometric identities)
>
> 2. Clamp it to range [-1.0:1.0]. You can do this in numpy with
> numpy.clip().
>
> Carl Banks
Thanks Carl. The "clip" task sounds a lot more reasonable. It would
be clever if I could find a way around using arcsin/arccos, I'll see
if that works for me. Yours is certainly the most practical advice on
this thread.
Adam
More information about the Python-list
mailing list