Floating point subtraction rounding error (NOT display error)

J. Robertson jr244 at kent.ac.uk
Fri Dec 14 10:56:42 EST 2007


Keflavich wrote:
> [snip]
 >
> I feel fairly certain, however, that floats are exactly what I want
> for my purposes: I need moderately high precision and I'm not
> concerned about the least-significant-bit errors except when they
> violate function domains.  I guess the overriding lesson is that every
> float subtraction needs to be carefully thought through, which is a
> disappointing loss of simplicity for me, but I'll deal with it.
> 
> Adam

floats probably are what you want, but in some corner cases you have to 
do further math in order for your computer not to blow up; an option may 
be to use Taylor expansions at some point before your function call, if 
you can see a case of problematic arguments creeping up like that.  And 
in general you have to use something like "abs(x-y) < epsilon" in place 
of x==y, as you said.

If it is simple enough, could you post the piece of code that leads to 
the x you use in arcsin(x)?  There's a chance that someone may figure a 
place where a numerical trick could be used in your code.



More information about the Python-list mailing list