Enable GMP Extension?

I wonder if it would be possible to enable the GMP Extension (http://php.net/manual/de/book.gmp.php) for the PHP Language. There are many useful function in there for mathematics which other languages have already builtin, would be nice to get some shorter solutions on some clashes!
For example there are prime number and gcd functions, which currently i have to do by hand :frowning:

2 Likes

C and C++ too please.

Yeah, it seems that the library is present on the system anyways and you can compile against it. For one of the puzzles which need arbitrarily big integers, I’ve used GMP by just writing code to a file, compiling it and then using system to execute it. Along the lines of:

#include “stdlib.h”
#include “stdio.h”
#include “string.h”

int main()
{
FILE *fp = fopen(“myprog.cpp”, “w”);
fprintf(fp, “#include “stdio.h”\n#include “gmp.h”\nint main()\n{ mpz_t zRES; mpz_init(zRES);\n”);
fprintf(fp, “return 0;}\n”);
fclose(fp);
system(“gcc myprog.cpp -lstdc++ -lgmp -lm -o myprog”);
system("./myprog");
return 0;
}

1 Like

I should definitely have thought about that.

Why not just use bash, though?

Clash of Code is totally unfair. I have met Pythonists using math.gcd(), but in PHP we can’t use gmp_gcd() function. I have lost some clashes only by missing GMP extension.