GMP division segfault

116 views Asked by At

I'm trying to build a library that does various mathematical operations with GMP so I can use it in place of floats, but I very quickly ran into issues because division doesn't appear to work. I tried the following in the console:

php > $a = gmp_init ("5");
php > $b = gmp_init ("2");
php > echo gmp_add ($a, $b) . PHP_EOL;
7
php > echo gmp_sub ($a, $b) . PHP_EOL;
3
php > echo gmp_mul ($a, $b) . PHP_EOL;
10
php > echo gmp_div_q ($a, $b) . PHP_EOL;
Segmentation fault: 11

I got the same result with the other GMP division functions. As far as I can tell I'm not doing anything wrong. In fact I even tried the examples directly from the PHP documentation and got the same result (a segfault).

I also tried it with values that can divide exactly and still got segfaults.

PHP version is:

PHP 7.1.0 (cli) (built: Dec 2 2016 09:19:56) ( NTS )

Am I doing something wrong or is this a bug?

EDIT: As it's a segfault I've logged a bug report for this issue. https://bugs.php.net/bug.php?id=73780

0

There are 0 answers