This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]