help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gsl] gsl precision question


From: Wally
Subject: [Help-gsl] gsl precision question
Date: Wed, 22 Feb 2012 10:13:59 +0100
User-agent: KMail/4.7.2 (Linux/3.1.9-1.4-desktop; KDE/4.7.2; i686; ; )

Hi,

i do not really get behind, how to mamge precision and rounding 
for gsl outputs. 
For example: For Euler and complex stuff a series of i^n , n= 0,1,2,...
is useful. Following code should do this but i guess during gsl internal 
calculation (log() ) the process loose precision and i get output as shown 
below. 

How can i tell gsl to use a certain precision and/or how to round ?  

I played with gsl_ieee_utils, but did not achieve wanted results.
 

#include <gsl/gsl_complex.h>
#include <gsl/gsl_complex_math.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_ieee_utils.h>

int main() {
int cnt;

    // export GSL_IEEE_MODE="single-precision, round-to-zero"
    // >env |grep GSL
    // GSL_IEEE_MODE=single-precision, round-to-zero

    gsl_ieee_env_setup (); // read GSL_IEEE_MODE

    for (cnt=0;cnt<13;cnt++) {

        gsl_complex z = gsl_complex_pow_real(gsl_complex_rect(0,1), cnt);

        printf("(%g,%g)\n", GSL_REAL(z), GSL_IMAG(z));
    }

return 0;
}




' gsl output:                   wanted output (i or 1 for imag)
' (1, 0)
' (6.12303e-17, 1)       ~     i
' (-1, 1.22461e-16)      ~    -1
' (-1.83691e-16, -1)     ~    -i 
' (1, -2.44921e-16)      ~     1
' (3.06152e-16, 1)       ~     i
' (-1, 3.67382e-16)      ~    -1
' (-4.28612e-16, -1)     ~    -i
' (1, -4.89843e-16)      ~     1
' (5.51073e-16, 1)       ~     i
' (-1, 6.12303e-16)      ~    -1 
' (-2.44989e-15, -1)     ~    -i
' (1, -7.34764e-16)      ~     1


regards wally



reply via email to

[Prev in Thread] Current Thread [Next in Thread]