variables erased ?

Patrick Pelissier Patrick.Pelissier at loria.fr
Tue Mar 15 17:19:32 CET 2005


chi.c:
#include <stdio.h>
#include "gmp.h"
#include "mpfr.h"

void print_mpfr (const char *string, mpfr_t m) {
 printf ("%s", string);
 mpfr_out_str (stdout, 10, 0, m, GMP_RNDN);
 putchar ('\n');
};
score_getChi2(double chi, unsigned int df)
/* ... */ 

gcc chi.c -lmpfr -lgmp

First library MPFR, then library GMP.

You get undefined reference to `__gmpfr_out_str'
because you use an header from MPFR 2.1.x
and a library from 2.0.x. Don't mix different version
of library and header!

You can try to link with the right library:

gcc chi.c /DIR/libmpfr.a -lgmp

where /DIR/ is the path to your libmpfr.a.

 Sincerely,
  Patrick Pelissier

> 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
> 

> >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