High fidelity (~ 200 sig figs) incomplete gamma function called in C
im wondering if anyone knows of any libraries that allow for very high precision (200+ sig figs, preferably just arbitrary) incomplete gamma ray functions? So far, the only one I've found is mpmath for python, but I have no idea how to include it in C code if possible.
It can be in any language, just as long as I can link it somehow and call it from C.
Greetings
source to share
I think the GNU MP Bignum library is exactly what you are looking for.
You can do things like:
#include <stdio.h>
#include <gmp.h>
int main(int argc, char *argv[]) {
mpz_t a, b, c;
if (argc<3) {
printf("Please supply two numbers to add.\n");
return 1;
}
mpz_init_set_str (a, argv[1], 10);
mpz_init_set_str (b, argv[2], 10);
mpz_add (c, a, b);
printf("%s + %s => %s\n", argv[1], argv[2], mpz_get_str (NULL, 10, c));
return 0;
Compile with: gcc -o add_example add_example.c -lgmp -lm
source to share
As an alternative route, you can use a math application that supports batch mode, such as Maxima , Mathematica, or Matlab .
I have tried the following Maxima script:
fpprec : 200;
fpprintprec : 200;
bfloat(gamma_incomplete(2,bfloat(2.3)));
Running it like this maxima -q -b ./incompletegamma.mc run
gives:
(%i1) batch("./gamma.mc")
read and interpret file: ./gamma.mc
(%i2) fpprec:200
(%o2) 200
(%i3) fpprintprec:1000
(%o3) 1000
(%i4) bfloat(gamma_incomplete(2,bfloat(2.3)))
(%o4) 3.3085418428525236227076532372691440857133290256546276037973522730841281\
226873248876116604879039570340226922621099906787322361219389317316508680513479\
116358485422369818232009561056364657588558639170139b-1
You can use system()
or call()
to run maxima script from python application like this:
from subprocess import call
call(["maxima", "-q -b ./incompletegamma.mc run"])
source to share