This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
little improvement
- From: Fabian <fseoane at wanadoo dot es>
- To: gsl-discuss at sources dot redhat dot com
- Date: Wed, 01 Sep 2004 15:18:34 +0200
- Subject: little improvement
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