little improvement
Fabian
fseoane@wanadoo.es
Wed Sep 1 13:45:00 GMT 2004
Hi!. (i'm not sure if this is the right way to do it)
I just thought that a method in complex/math.c could be improved.
The method is very simple, it is :
gsl_complex
gsl_complex_inverse (gsl_complex a)
{ /* z=1/a */
double s = 1.0 / gsl_complex_abs (a);
gsl_complex z;
GSL_SET_COMPLEX (&z, (GSL_REAL (a) * s) * s, -(GSL_IMAG (a) *
s) * s);
return z;
}
I just thought that if you set s to "1.0 / gsl_complex_abs2 (a)" which
is less expensive that the original and in addition you can avoid the
multiplications in GSL_SET_COMPLEX, so that it turns in something like
this
GSL_SET_COMPLEX (&z, (GSL_REAL (a) * s), -(GSL_IMAG (a) * s) );
my complete code is something like this:
gsl_complex
gsl_complex_inverse (gsl_complex a)
{ /* z=1/a */
double s = 1.0 / gsl_complex_abs2 (a);
gsl_complex z;
GSL_SET_COMPLEX (&z, (GSL_REAL (a) * s), -(GSL_IMAG (a) * s)
);
return z;
}
That's all. I'm quite a novice and my english isn't very good, so please
excuse me if miss something
More information about the Gsl-discuss
mailing list