From: Philipp Stephani Date: Wed, 24 Apr 2019 11:54:54 +0000 (+0200) Subject: * doc/lispref/internals.texi (Module Values): Add a GMP example X-Git-Tag: emacs-27.0.90~3109 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b6d8d34aede02a6af7a614f32b86292ee4ba1757;p=emacs.git * doc/lispref/internals.texi (Module Values): Add a GMP example --- diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi index 3e6488a5ccf..5ae71afbef2 100644 --- a/doc/lispref/internals.texi +++ b/doc/lispref/internals.texi @@ -1543,6 +1543,31 @@ integral object. After you have finished using or similar. @end deftypefn +The following example uses GMP to calculate the next probable prime +after a given integer: + +@example +#include +#include + +#define EMACS_MODULE_GMP +#include + +static emacs_value +next_prime (emacs_env *env, ptrdiff_t nargs, emacs_value *args, + void *data) +@{ + assert (nargs == 1); + emacs_mpz p; + mpz_init (p.value); + env->extract_big_integer (env, args[0], &p); + mpz_nextprime (p.value, p.value); + emacs_value result = env->make_big_integer (env, &p); + mpz_clear (p.value); + return result; +@} +@end example + The @acronym{API} does not provide functions to manipulate Lisp data structures, for example, create lists with @code{cons} and @code{list} (@pxref{Building Lists}), extract list members with @code{car} and