mpz_set_d dumping core

sisyphus1 at optusnet.com.au sisyphus1 at optusnet.com.au
Mon Aug 22 08:44:35 UTC 2016


Hi,

What is the intended behaviour when the double provided to mpz_set_d is an 
inf or a nan ?
Neither the mpz_init_set_d nor the mpz_set_d documentation on the website 
specify the consequences of doing that.

With gmp-6.1.1 on linux, I'm getting a "Floating point exception (core 
dumped)" message:

###############################
$ cat mpz_set_d.c

#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>

int main(void) {
mpz_t z;
double d;

d = strtod("inf", NULL);

printf("%e\n%s\n", d, gmp_version);

mpz_init_set_d(z, d);

printf("OK so far\n");

mpz_clear(z);
return 0;
}

$ gcc -o mpz_set_d.exe mpz_set_d.c -lgmp
$ ./mpz_set_d.exe
inf
6.1.1
Floating point exception (core dumped)

###############################

On windows it's even less graceful -  the function call causes the program 
to abort without any message at all if the double is an inf/nan.

Cheers,
Rob 



More information about the gmp-discuss mailing list