possible problems with mpfr

Scott Bucholtz linuxman at nmt.edu
Sat Feb 21 14:00:55 CET 2004

Hello all,

I am having two problems with Lib-GMP's mpfr implementation.  I am sure 
that I'm doing something wrong but can't figure it out.  I am using 
Lib-GMP v4.1.2 compiled with --enable-cxx and --enable-mpfr.  I have GCC 
2.95.3 and ld 2.11.2 but have also tried it with GCC 3.2 and ld 2.13.

The following code exhibits both of my problems:

 * Compile:  gcc isint_test.c -Wall -lgmp -lmpfr -o isint_test
 * For some reason, the order of the compile options is important here.
 * If I try this compile line:  gcc -Wall -lgmp -lmpfr -o isint_test isint_test.c
 * then it does not compile (i.e., cannot resolve mpfr functions).
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include <mpfr.h>

int main(void) {
  mpfr_t x;

  printf("x is set to ");

  printf("\nAfter floor, x is ");

  printf("\nmpfr_isinteger(x) returned %d\n",mpfr_isinteger(x));
  if( mpfr_cmp_ui(x,0L)==0 ) printf("mpfr_cmp_ui claims x is 0\n");

First (as the comments say), when I change the order of the compilation 
command line, I get linker errors about undefined references to the mpfr 
functions.  This is weird.  However, the much more important issue, is my 
problem with the mpfr_isinteger() function.  If I actually want it to work 
correctly when the mpfr_t equals zero, I need to set it to 1 using 
mpfr_set_ui() then subtract 1 like this:

        if( mpfr_cmp_ui(x,0L)==0 ) {

This only seems to be a problem when the mpfr_t equals zero exactly (such 
as in this above floor() function).

Any help or ideas?  Thank you very much.

Scott Bucholtz
IT System Engineer for Research and Development
Honeywell FM&T/NM
work:   (505) 661-8496
cell:   (505) 570-3000

More information about the gmp-bugs mailing list