variables erased ?

Nicolas Peyrussie nicolas.peyrussie at laposte.net
Tue Mar 15 16:51:09 CET 2005


I already tried this and I get this message :
score.c:172: undefined reference to `__gmpfr_out_str'

when I compile with options -lgmp and -lmpfr

Regards,
Nicolas Peyrussie

Patrick Pelissier wrote:

>chi.c: In function `score_getChi2':
>chi.c:19: warning: double format, pointer arg (arg 2)
>chi.c:21: warning: double format, pointer arg (arg 2)
>chi.c:23: warning: double format, pointer arg (arg 2)
>chi.c:25: warning: double format, pointer arg (arg 2)
>chi.c:27: warning: double format, pointer arg (arg 2)
>chi.c:34: warning: double format, pointer arg (arg 2)
>
> You are giving a mpfr_t to printf, and you print it like a double.
> You can't display mpfr_t with printf without using printf extension.
>
> Use this instead:
>
>void print_mpfr (const char *string, mpfr_t m) {
> printf ("%s", string);
> mpfr_out_str (stdout, 10, 0, m, GMP_RNDN);
> putchar ('\n');
>};
>
> Sincerely,
>  Patrick Pelissier
>
>On Tue, Mar 15, 2005 at 16:28:25 +0100, Nicolas Peyrussie wrote:
>  
>
>>Hello,
>>
>>I am using gmp and mpfr to do some calculations (inversed Chi squared 
>>function) and I have a trouble with the variables initialization.
>>This is my code :
>>/*************************************************/
>>void score_getChi2(double chi, unsigned int df)
>>{
>>mpfr_t sum,term, temp, tmp ,m, mm;
>>unsigned int i=1;
>>
>>mpfr_init(sum);
>>mpfr_init(term);
>>mpfr_init(temp);
>>mpfr_init(tmp);
>>mpfr_init(m);
>>mpfr_init(mm);
>>
>>  printf("chi : %f\n", chi);
>>mpfr_set_d(m, chi / 2.0, GMP_RNDN);
>>  printf("m : %F\n", m);
>>mpfr_neg(mm,m, GMP_RNDD);
>>  printf("mm : %F\n", mm);
>>mpfr_exp(tmp, m, GMP_RNDN);
>>  printf("%F\n", tmp);
>>mpfr_set(sum, tmp, GMP_RNDN);
>>  printf("%F\n", sum);
>>mpfr_set(term, tmp, GMP_RNDN);
>>  printf("%F\n", term);
>>
>>for(i=1;i<=df/2;i++){
>>  mpfr_div_ui(temp, m, i, GMP_RNDN);
>>  mpfr_mul(term, term, temp, GMP_RNDN);
>>  mpfr_add(sum, sum, term, GMP_RNDN);
>>}
>>  printf("%F\n", sum);
>>}
>>/*************************************************/
>>
>>After the mpfr_set_d(m, chi / 2.0, GMP_RNDN); that is OK, I display the 
>>right value (for "m"), but then I just get zeros for all the others...
>>If I try to display "m" avec the mpfr_set_neg(mm,m, GMP_RNDD); I also 
>>have 0.
>>I don't understand why I get just zeros for my variables and also why I 
>>get 0 for "m" when I am supposed not to touch to its value when I do 
>>mpfr_set_neg(mm,m, GMP_RNDD);
>>
>>I read the manual entries for these functions but I found nothing 
>>related to this problem.
>>Does someone have a solution ?
>>I thank you in advance.
>>
>>Regards,
>>Nicolas
>>_______________________________________________
>>gmp-discuss mailing list
>>gmp-discuss at swox.com
>>https://gmplib.org/mailman/listinfo/gmp-discuss
>>    
>>



More information about the gmp-discuss mailing list