variables erased ???

delta trinity deltatrinity at hotmail.com
Wed Mar 16 02:16:21 CET 2005


Bonjour!

I'm not sure if it's because of that, but definitely, you can't use printf 
with GMP variables.

The 'gmp_printf' function is available for that.  It work exactly like 
printf, but extend the possible type specifiers (as you used in printf).

Eric

>From: Nicolas Peyrussie <nicolas.peyrussie at laposte.net>
>To: gmp-discuss at swox.com
>Subject: variables erased ???
>Date: Tue, 15 Mar 2005 16:19:04 +0100
>
>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