Niels Möller nisse at
Wed Dec 28 15:13:46 CET 2011

After discussion with Torbjörn and some other GNU people (this started
as something like "Why does guile depend on GMP??? I'm using it as an
extension language for my application. I don't need any bignums (or at
least not any particularly efficient ones) and I don't want to bother my
users or developers with installing GMP"), I've started to put together
"mini-gmp", with the below README.

  This is "mini-gmp", a small implementation of a subset of GMP's mpn
  and mpz interfaces.
  It is intended for applications which need arithmetic on numbers
  larger than a machine word, but which don't need to handle very large
  numbers very efficiently. Those applications can include a copy of
  mini-gmp to get a GMP-compatible interface with small footprint. One
  can also arrange for optional linking with the real GMP library, using
  mini-gmp as a fallback when for some reason GMP is not available, or
  not desired as a dependency.
  The supported GMP subset is declared in mini-gmp.h. The implementation
  is a single file, mini-gmp.c.
  The performance target for mini-gmp is to be at most 10 times slower
  than the real GMP library, for numbers of size up to a few hundred
  bits. No asymptotically fast algorithms are included in mini-gmp, so
  it will be many orders of magnitude slower than GMP for very large
  You should never "install" mini-gmp. Applications can either just
  #include mini-gmp.c (but then, beware that it defines several macros
  and functions outside of the advertised interface). Or compile
  mini-gmp.c as a separate compilation unit, and use the declarations in
  The tests subdirectory contains a testsuite. To use it, you need GMP
  and GNU make. Just run make check in the tests directory. If the
  hardcoded compiler settings are not right, you have to either edit the
  Makefile or pass overriding values on the make command line (e.g.,
  make CC=cc check). Testing is not (yet) as thorough as for the real
  The current version was put together by Niels Möller
  <nisse at>, with a fair amount of copy-and-paste from the
  GMP sources.

Comments appreciated. Exactly what GMP subset to implement is not
entirely clear. Definitely missing are gcd, square root, and more
general get_str and set_str (and then lots of variants of the existing
functions, mpz_*div_q, mpz_*div_r, init_set, etc).

It would be nice to have gcc not depend on GMP, but that's a bit more
tricky, since the dependency is via mpfr (and mpc?).

The repository is at (or
/var/hg/gmp-proj/mini-gmp on shell).


Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.

More information about the gmp-devel mailing list