Floating-point glitches with the math module. Bug? Or am I missing something?

Paul Rubin http
Wed Sep 22 23:07:17 CEST 2004

Alexandre Fayolle <alf at merlin.fayauffre.org> writes:
> Firstly, I use the fact that scipy provides a cosm1 function which 
> returns cos(x)-1, and which is more precise that for small values of x. 

The simple approximation is cos(x)-1 = -x**2/2.  Fancier approximation
is cos(x)-1 = -x**2/2 + x**4/24, which should exceed machine precision
for x < 2**-12 or so.

> Then I'd like to use an acosm1 function in order to keep the precision.
> Since there is no such function available, I'll just solve
> cosm1(x)-cos_gamma_minus_1=0 for which I know there is a solution

acosm1(x) = sqrt(-2*x) for the simple approximation.  Use quadratic
formula to solve the fancier one.

More information about the Python-list mailing list