variables erased ???

Nicolas Peyrussie nicolas.peyrussie at laposte.net
Tue Mar 15 16:19:04 CET 2005


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


More information about the gmp-discuss mailing list