Commit ddd6fe77 authored by simonmar's avatar simonmar

[project @ 2000-08-18 15:44:25 by simonmar]

Import stripped-down gmp-3.1.

This will cause severe breakage until I can resolve the conflicts and
check in the rest of the changes, so I'd advise not updating this
directory for a while (unless you're using a system-installed gmp, in
which case it won't matter).
parent 24a7fdbd
Authors if GNU MP (in chronological order)
Torbjrn Granlund
John Amanatides
Paul Zimmermann
Ken Weber
Bennet Yee
Andreas Schwab
Robert Harley
Linus Nordberg
Kent Boortz
Kevin Ryde
Guillaume Hanrot
No preview for this file type
This diff is collapsed.
INSTALLING GMP
==============
INSTALLING GNU MP
=================
These instructions are only for the impatient. Others should read the install
instructions in the manual, gmp.info. Use "info -f gmp.info", or, if you
don't have info, use type "C-h i g (gmp.info)Top" in emacs.
instructions in the manual, gmp.info. Use
info -f ./gmp.info
or in emacs
Here are short instructions how to install MP, and some examples that help you
get started using MP.
C-u C-h i gmp.info
First, you need to compile, and optionally install, MP. Since you're
Here are some brief instructions on how to install GMP, and some examples to
help you get started using GMP.
First, you need to compile, and optionally install, GMP. Since you're
impatient, try this:
./configure; make
If that fails, or you care about the performance of MP, you need to read the
full instructions in the chapter "Installing MP", in the manual.
If that fails, or you care about the performance of GMP, you need to read the
full instructions in the chapter "Installing GMP", in the manual.
Next, try some small test programs, for example the ones below.
Next, you need to try some small test programs, for example the ones below.
In GMP programs, all variables need to be initialized before they are
assigned, and cleared out before program flow leaves the scope in which they
were declared. Here is an example program that reads two numbers from the
command line, multiplies them, and prints the result to stdout.
In MP programs, all variables need to be initialized before they are assigned,
and cleared out before program flow leaves the scope in which it was declared.
Here is an example of a program that reads two numbers from the command line,
multiplies them, and prints the result to stdout.
#include <stdio.h>
#include <gmp.h> /* All MP programs need to include gmp.h */
#include <gmp.h> /* All GMP programs need to include gmp.h */
main (int argc, char **argv)
{
mpz_t a, b, p;
if (argc != 3)
{ printf ("Usage: %s <number> <number>\n", argv[0]); exit (1); }
/* Initialize variables */
mpz_init (a);
mpz_init (b);
......@@ -54,7 +66,10 @@ multiplies them, and prints the result to stdout.
}
In practice, that example would be written like this instead:
This might look tedious, with all the initializing and clearing. Fortunately
some of these operations can be combined, and other operations can often be
avoided. An experienced GMP user might write:
#include <stdio.h>
#include <gmp.h>
......@@ -63,6 +78,9 @@ In practice, that example would be written like this instead:
{
mpz_t a, b, p;
if (argc != 3)
{ printf ("Usage: %s <number> <number>\n", argv[0]); exit (1); }
/* Initialize and assign a and b from base 10 strings in argv */
mpz_init_set_str (a, argv[1], 10);
mpz_init_set_str (b, argv[2], 10);
......@@ -80,75 +98,49 @@ In practice, that example would be written like this instead:
exit (0);
}
Finally, you have to compile your test program, and link it with the MP
library. Assuming your working directory is still the gmp source directory,
type:
gcc -g -I. example.c libgmp.a
Now you have to compile your test program, and link it with the GMP library.
Assuming your working directory is still the gmp source directory, and your
source file is called example.c, enter:
gcc -g -I. example.c .libs/libgmp.a
After installing, the command becomes: "gcc -g example.c -lgmp". Also, GMP is
libtool based so you can use that to link if you want.
Now try to run the example:
a.out 98365871231256752134 319378318340103345227
./a.out 98365871231256752134 319378318340103345227
31415926535897932384618573336104570964418
The functions used here all operate on the domain of signed integers.
Functions operating on that domain have names starting with "mpz_". There are
many more such functions than used in these examples. See the chapter
"Integer Functions" in the manual, for a complete list.
The functions used here all operate on signed integers, and have names
starting with "mpz_". There are many more such functions than used in these
examples. See the chapter "Integer Functions" in the manual, for a complete
list.
There are two other main classes of functions in MP. They operate on rational
numbers and floating-point numbers, respectively. The chapters "Rational
Number Functions", and "Floating-point Functions" documents these classes.
There are two other main classes of functions in GMP. They operate on
rational numbers and floating-point numbers, respectively. The chapters
"Rational Number Functions", and "Floating-point Functions" document these
classes.
To run a set of tests, do "make check". This will take a while.
To create the printable documentation from the texinfo source, type "make
dvi". This requires the "tex" command to be available in your search path.
gmp.dvi" or "make gmp.ps". This requires various "tex" commands.
To install the library, do "make install".
To install the library, do "make install" (then you can use -lgmp instead of
.libs/libgmp.a).
If you decide to use MP, It is a good idea you read at least the chapter "MP
If you decide to use GMP, it is a good idea you at least read the chapter "GMP
Basics" in the manual.
Some known build problems are noted in the "Installing GMP" chapter of
the manual. Please report other problems to bug-gmp@gnu.org.
Known Build Problems
--------------------
Note that GCC 2.7.2 (as well as 2.6.3) for the RS/6000 and PowerPC can not
be used to compile GMP, due to a bug in GCC. If you want to use GCC, you
need to apply the patch at the end of this file, or use a later version of
the compiler.
If you are on a Sequent Symmetry, use GAS instead of the system's assembler
due to the latter's serious bugs.
The system compiler on NeXT is a massacred and old gcc, even if the
compiler calls itself cc. This compiler cannot be used to build GMP. You
need to get a real gcc, and install that before you compile GMP. (NeXT
might have fixed this in newer releases of their system.)
Please report other problems to bug-gmp@prep.ai.mit.edu.
Patch to apply to GCC 2.6.3 and 2.7.2:
*** config/rs6000/rs6000.md Sun Feb 11 08:22:11 1996
--- config/rs6000/rs6000.md.new Sun Feb 18 03:33:37 1996
***************
*** 920,926 ****
(set (match_operand:SI 0 "gpc_reg_operand" "=r")
(not:SI (match_dup 1)))]
""
! "nor. %0,%2,%1"
[(set_attr "type" "compare")])
(define_insn ""
--- 920,926 ----
(set (match_operand:SI 0 "gpc_reg_operand" "=r")
(not:SI (match_dup 1)))]
""
! "nor. %0,%1,%1"
[(set_attr "type" "compare")])
(define_insn ""
----------------
Local variables:
mode: text
fill-column: 78
End:
## Process this file with automake to generate Makefile.in
# Copyright (C) 1991, 1993, 1994, 1996, 1997, 1999, 2000 Free Software
# Foundation, Inc.
#
# This file is part of the GNU MP Library.
#
# The GNU MP Library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or (at your
# option) any later version.
#
# The GNU MP Library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with the GNU MP Library; see the file COPYING.LIB. If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
# MA 02111-1307, USA.
# make check
#
# It'd be good if "make check" first did a "make all" or whatever to
# build libgmp.la, but it's not clear how best to do this. Putting a
# "check:" target is overridden by automake, and a "check-local:" runs
# too late (due to depth-first subdirectory processing). For now it's
# necessary to do "make && make check".
#
# MPF_OBJECTS etc
#
# Libtool needs all the .lo files passed to it if it's going to build
# both a static and shared library. If a convenience library like
# mpf/libmpf.la is passed then the resulting libgmp.a gets the PIC .lo
# objects rather than the non-PIC .o's.
#
# Unfortunately this leads to the big lists of objects below. Something
# like mpz/*.lo would probably work, but might risk missing something
# out or getting something extra. The source files for each .lo are
# listed in the Makefile.am's in the subdirectories.
# Libtool -version-info for libgmp.la and libmp.la. See (libtool)Versioning
#
# 1. No interfaces changed, only implementations (good): Increment REVISION.
#
# 2. Interfaces added, none removed (good): Increment CURRENT, increment
# AGE, set REVISION to 0.
#
# 3. Interfaces removed (BAD, breaks upward compatibility): Increment
# CURRENT, set AGE and REVISION to 0.
#
# Do this separately for libgmp and libmp, only do it just before a release.
#
# GMP -version-info
# release libgmp libmp
# 2.0.x - -
# 3.0 3:0:0 3:0:0
# 3.0.1 3:1:0 3:0:0
# 3.1 4:0:1 4:0:1
#
#
# Starting at 3:0:0 is a slight abuse of the versioning system, but it
# ensures we're past soname libgmp.so.2, which is what has been used on
# Debian GNU/Linux packages of gmp 2. Pretend gmp 2 was 2:0:0, so the
# interface changes for gmp 3 mean 3:0:0 is right.
LIBGMP_LT_CURRENT = 4
LIBGMP_LT_REVISION = 0
LIBGMP_LT_AGE = 1
LIBMP_LT_CURRENT = 4
LIBMP_LT_REVISION = 0
LIBMP_LT_AGE = 1
AUTOMAKE_OPTIONS = gnu check-news no-dependencies ansi2knr
SUBDIRS = mpn mpz mpq mpf mpbsd mpfr tests demos tune
include_HEADERS = gmp.h $(MPBSD_HEADERS_OPTION) $(MPFR_HEADERS_OPTION)
EXTRA_HEADERS = mp.h
lib_LTLIBRARIES = libgmp.la $(MPBSD_LTLIBRARIES_OPTION)
EXTRA_DIST = .gdbinit gmp-impl.h longlong.h stack-alloc.h urandom.h doc macos
DISTCLEANFILES = asm-syntax.h config.m4 @gmp_srclinks@
MPF_OBJECTS = mpf/init.lo mpf/init2.lo mpf/set.lo mpf/set_ui.lo mpf/set_si.lo \
mpf/set_str.lo mpf/set_d.lo mpf/set_z.lo mpf/iset.lo mpf/iset_ui.lo \
mpf/iset_si.lo mpf/iset_str.lo mpf/iset_d.lo mpf/clear.lo mpf/get_str.lo \
mpf/dump.lo mpf/size.lo mpf/eq.lo mpf/reldiff.lo mpf/sqrt.lo mpf/random2.lo \
mpf/inp_str.lo mpf/out_str.lo mpf/add.lo mpf/add_ui.lo mpf/sub.lo \
mpf/sub_ui.lo mpf/ui_sub.lo mpf/mul.lo mpf/mul_ui.lo mpf/div.lo \
mpf/div_ui.lo mpf/cmp.lo mpf/cmp_ui.lo mpf/cmp_si.lo mpf/mul_2exp.lo \
mpf/div_2exp.lo mpf/abs.lo mpf/neg.lo mpf/set_q.lo mpf/get_d.lo \
mpf/set_dfl_prec.lo mpf/set_prc.lo mpf/set_prc_raw.lo mpf/get_prc.lo \
mpf/ui_div.lo mpf/sqrt_ui.lo mpf/floor.lo mpf/ceil.lo mpf/trunc.lo \
mpf/pow_ui.lo mpf/urandomb.lo mpf/swap.lo
MPZ_OBJECTS = mpz/abs.lo mpz/add.lo mpz/add_ui.lo mpz/addmul_ui.lo mpz/and.lo \
mpz/array_init.lo mpz/bin_ui.lo mpz/bin_uiui.lo mpz/cdiv_q.lo \
mpz/cdiv_q_ui.lo mpz/cdiv_qr.lo mpz/cdiv_qr_ui.lo mpz/cdiv_r.lo \
mpz/cdiv_r_ui.lo mpz/cdiv_ui.lo mpz/clear.lo mpz/clrbit.lo mpz/cmp.lo \
mpz/cmp_si.lo mpz/cmp_ui.lo mpz/cmpabs.lo mpz/cmpabs_ui.lo mpz/com.lo \
mpz/divexact.lo mpz/dump.lo mpz/fac_ui.lo mpz/fdiv_q.lo mpz/fdiv_q_2exp.lo \
mpz/fdiv_q_ui.lo mpz/fdiv_qr.lo mpz/fdiv_qr_ui.lo mpz/fdiv_r.lo \
mpz/fdiv_r_2exp.lo mpz/fdiv_r_ui.lo mpz/fdiv_ui.lo mpz/fib_ui.lo \
mpz/fits_sint_p.lo mpz/fits_slong_p.lo mpz/fits_sshort_p.lo \
mpz/fits_uint_p.lo mpz/fits_ulong_p.lo mpz/fits_ushort_p.lo mpz/gcd.lo \
mpz/gcd_ui.lo mpz/gcdext.lo mpz/get_d.lo mpz/get_si.lo mpz/get_str.lo \
mpz/get_ui.lo mpz/getlimbn.lo mpz/hamdist.lo mpz/init.lo mpz/inp_raw.lo \
mpz/inp_str.lo mpz/invert.lo mpz/ior.lo mpz/iset.lo mpz/iset_d.lo \
mpz/iset_si.lo mpz/iset_str.lo mpz/iset_ui.lo mpz/jacobi.lo \
mpz/kronsz.lo mpz/kronuz.lo mpz/kronzs.lo mpz/kronzu.lo \
mpz/lcm.lo mpz/legendre.lo \
mpz/mod.lo mpz/mul.lo mpz/mul_2exp.lo mpz/mul_si.lo mpz/mul_ui.lo \
mpz/neg.lo mpz/nextprime.lo mpz/out_raw.lo mpz/out_str.lo mpz/perfpow.lo mpz/perfsqr.lo \
mpz/popcount.lo mpz/pow_ui.lo mpz/powm.lo mpz/powm_ui.lo mpz/pprime_p.lo \
mpz/random.lo mpz/random2.lo mpz/realloc.lo mpz/remove.lo mpz/root.lo \
mpz/rrandomb.lo \
mpz/scan0.lo mpz/scan1.lo mpz/set.lo mpz/set_d.lo mpz/set_f.lo mpz/set_q.lo \
mpz/set_si.lo mpz/set_str.lo mpz/set_ui.lo mpz/setbit.lo mpz/size.lo \
mpz/sizeinbase.lo mpz/sqrt.lo mpz/sqrtrem.lo mpz/sub.lo mpz/sub_ui.lo \
mpz/swap.lo mpz/tdiv_ui.lo mpz/tdiv_q.lo mpz/tdiv_q_2exp.lo mpz/tdiv_q_ui.lo \
mpz/tdiv_qr.lo mpz/tdiv_qr_ui.lo mpz/tdiv_r.lo mpz/tdiv_r_2exp.lo \
mpz/tdiv_r_ui.lo mpz/tstbit.lo mpz/ui_pow_ui.lo mpz/urandomb.lo \
mpz/urandomm.lo mpz/xor.lo
MPQ_OBJECTS = mpq/add.lo mpq/canonicalize.lo mpq/clear.lo mpq/cmp.lo \
mpq/cmp_ui.lo mpq/div.lo mpq/get_d.lo mpq/get_den.lo mpq/get_num.lo \
mpq/init.lo mpq/inv.lo mpq/mul.lo mpq/neg.lo mpq/out_str.lo \
mpq/set.lo mpq/set_den.lo \
mpq/set_num.lo mpq/set_si.lo mpq/set_ui.lo mpq/sub.lo mpq/equal.lo \
mpq/set_z.lo mpq/set_d.lo mpq/swap.lo
MPN_OBJECTS = @mpn_objs_in_libgmp@
MPBSD_OBJECTS = mpbsd/add.lo mpbsd/tdiv_qr.lo mpbsd/move.lo mpbsd/powm.lo \
mpbsd/sub.lo mpbsd/cmp.lo mpbsd/mfree.lo mpbsd/mtox.lo mpbsd/realloc.lo \
mpbsd/gcd.lo mpbsd/itom.lo mpbsd/min.lo mpbsd/mul.lo mpbsd/mout.lo \
mpbsd/pow_ui.lo mpbsd/sdiv.lo mpbsd/sqrtrem.lo mpbsd/xtom.lo
# FIXME: Add mpfr/rnd_mode.lo when it's clean.
MPFR_OBJECTS = mpfr/add.lo mpfr/div_2exp.lo mpfr/neg.lo mpfr/set_dfl_prec.lo \
mpfr/set_str_raw.lo mpfr/agm.lo mpfr/get_str.lo mpfr/print_raw.lo \
mpfr/set_dfl_rnd.lo mpfr/sqrt.lo mpfr/clear.lo mpfr/init.lo \
mpfr/set_f.lo mpfr/sub.lo mpfr/cmp.lo mpfr/mul.lo mpfr/round.lo \
mpfr/set_prec.lo mpfr/cmp_ui.lo mpfr/mul_2exp.lo mpfr/set.lo mpfr/set_si.lo \
mpfr/div.lo mpfr/mul_ui.lo mpfr/set_d.lo mpfr/pow.lo mpfr/out_str.lo \
mpfr/pi.lo mpfr/set_z.lo mpfr/add_ulp.lo mpfr/log2.lo mpfr/random.lo \
mpfr/log.lo mpfr/exp.lo mpfr/div_ui.lo mpfr/zeta.lo mpfr/karadiv.lo \
mpfr/karasqrt.lo mpfr/print_rnd_mode.lo
if WANT_MPFR
MPFR_HEADERS_OPTION = mpfr/mpfr.h
MPFR_OBJECTS_OPTION = $(MPFR_OBJECTS)
MPFR_LIBADD_OPTION = -lm
endif
libgmp_la_SOURCES = assert.c compat.c errno.c memory.c mp_set_fns.c \
mp_clz_tab.c mp_minv_tab.c \
rand.c randclr.c randlc.c randlc2x.c randraw.c randsd.c \
randsdui.c version.c stack-alloc.c mp_bpl.c extract-dbl.c insert-dbl.c
libgmp_la_DEPENDENCIES = \
$(MPF_OBJECTS) $(MPZ_OBJECTS) $(MPN_OBJECTS) $(MPQ_OBJECTS) \
$(MPFR_OBJECTS_OPTION)
libgmp_la_LIBADD = $(libgmp_la_DEPENDENCIES) $(MPFR_LIBADD_OPTION)
libgmp_la_LDFLAGS = \
-version-info $(LIBGMP_LT_CURRENT):$(LIBGMP_LT_REVISION):$(LIBGMP_LT_AGE)
if WANT_MPBSD
MPBSD_HEADERS_OPTION = mp.h
MPBSD_LTLIBRARIES_OPTION = libmp.la
endif
libmp_la_SOURCES = assert.c errno.c memory.c mp_bpl.c mp_clz_tab.c \
mp_minv_tab.c mp_set_fns.c stack-alloc.c
libmp_la_DEPENDENCIES = $(MPBSD_OBJECTS) $(MPN_OBJECTS) \
mpz/add.lo mpz/clear.lo mpz/cmp.lo mpz/init.lo mpz/mod.lo mpz/mul.lo \
mpz/mul_2exp.lo mpz/realloc.lo mpz/set.lo mpz/set_ui.lo mpz/tdiv_r.lo \
mpz/sub.lo
libmp_la_LIBADD = $(libmp_la_DEPENDENCIES)
libmp_la_LDFLAGS = \
-version-info $(LIBMP_LT_CURRENT):$(LIBMP_LT_REVISION):$(LIBMP_LT_AGE)
info_TEXINFOS = gmp.texi
# Don't ship CVS directories or emacs backups.
dist-hook:
-find $(distdir) \( -name CVS -type d \) -o -name "*.~*" \
| xargs rm -rf
NOTEWORTHY CHANGES IN GNU MP IN VERSION 2
Changes between MP version 3.0 and 3.1
* Bug fixes.
* Improved `make check' running more tests.
* Tuned algorithm cutoff points for many machines. This will improve speed for
a lot of operations, in some cases by a large amount.
* Major speed improvments: Alpha 21264.
* Some speed improvments: Cray vector computers, AMD K6 and Athlon, Intel P5
and Pentium Pro/II/III.
* The mpf_get_prec function now works as it did in GMP 2.
* New utilities for auto-tuning and speed measuring.
* Multiplication now optionally uses FFT for very large operands. (To enable
it, pass --enable-fft to configure.)
* Support for new systems: Solaris running on x86, FreeBSD 5, HP-UX 11, Cray
vector computers, Rhapsody, Nextstep/Openstep, MacOS.
* Support for shared libraries on 32-bit HPPA.
* New integer functions: mpz_mul_si, mpz_odd_p, mpz_even_p.
* New Kronecker symbol functions: mpz_kronecker_si, mpz_kronecker_ui,
mpz_si_kronecker, mpz_ui_kronecker.
* New rational functions: mpq_out_str, mpq_swap.
* New float functions: mpf_swap.
* New mpn functions: mpn_divexact_by3c, mpn_tdiv_qr.
* New EXPERIMENTAL function layer for accurate floating-point arithmetic, mpfr.
To try it, pass --enable-mpfr to configure. See the mpfr subdirectory for
more information; it is not documented in the main GMP manual.
Changes between MP version 3.0 and 3.0.1
* Memory leaks in gmp_randinit and mpz_probab_prime_p fixed.
* Documentation for gmp_randinit fixed. Misc documentation errors fixed.
Changes between MP version 2.0 and 3.0
* Source level compatibility with past releases (except mpn_gcd).
* Bug fixes.
* Much improved speed thanks to both host independent and host dependent
optimizations.
* Switch to autoconf/automake/libtool.
* Support for building libgmp as a shared library.
* Multiplication and squaring using 3-way Toom-Cook.
* Division using the Burnikel-Ziegler method.
* New functions computing binomial coefficients: mpz_bin_ui, mpz_bin_uiui.
* New function computing Fibonacci numbers: mpz_fib_ui.
* New random number generators: mpf_urandomb, mpz_rrandomb, mpz_urandomb,
mpz_urandomm, gmp_randclear, gmp_randinit, gmp_randinit_lc_2exp, gmp_randseed,
gmp_randseed_ui.
* New function for quickly extracting limbs: mpz_getlimbn.
* New functions performing integer size tests: mpz_fits_sint_p,
mpz_fits_slong_p, mpz_fits_sshort_p, mpz_fits_uint_p, mpz_fits_ulong_p,
mpz_fits_ushort_p.
* New mpf functions: mpf_ceil, mpf_floor, mpf_pow_ui, mpf_trunc.
* New mpq function: mpq_set_d.
* New mpz functions: mpz_addmul_ui, mpz_cmpabs, mpz_cmpabs_ui, mpz_lcm,
mpz_nextprime, mpz_perfect_power_p, mpz_remove, mpz_root, mpz_swap,
mpz_tdiv_ui, mpz_tstbit, mpz_xor.
* New mpn function: mpn_divexact_by3.
* New CPU support: DEC Alpha 21264, AMD K6 and Athlon, HPPA 2.0 and 64,
Intel Pentium Pro and Pentium-II/III, Sparc 64, PowerPC 64.
* Almost 10 times faster mpz_invert and mpn_gcdext.
* The interface of mpn_gcd has changed.
* Better support for MIPS R4x000 and R5000 under Irix 6.
* Improved support for SPARCv8 and SPARCv9 processors.
Changes between MP version 2.0 and 2.0.2
* Many bug fixes.
Changes between MP version 1.3.2 and 2.0
* Division routines in the mpz class have changed. There are three classes of
functions, that rounds the quotient to -infinity, 0, and +infinity,
......@@ -38,7 +105,7 @@ NOTEWORTHY CHANGES IN GNU MP IN VERSION 2
* Uses GNU configure. This makes it possible to choose target architecture
and CPU variant, and to compile into a separate object directory.
* Carefully optimized assembly for important inner loops. Support for DEC
Alpha, Amd 29000, HPPA 1.0 and 1.1, Intel pentium and generic x86, Intel
Alpha, Amd 29000, HPPA 1.0 and 1.1, Intel Pentium and generic x86, Intel
i960, Motorola MC68000, MC68020, MC88100, and MC88110, Motorola/IBM
PowerPC, National NS32000, IBM POWER, MIPS R3000, R4000, SPARCv7,
SuperSPARC, generic SPARCv8, and DEC VAX. Some support also for ARM,
......@@ -54,3 +121,11 @@ INCOMPATIBILITIES BETWEEN GMP 1 AND GMP 2
* mpz division functions round differently.
* mpz mod functions now really compute mod.
* mpz_powm and mpz_powm_ui now really use mod for reduction.
----------------
Local variables:
mode: text
fill-column: 76
End:
THE GNU MP LIBRARY
GNU MP is a library for arbitrary precision arithmetic, operating on signed
integers, rational numbers, and floating point numbers. It has a rich set
of functions, and the functions have a regular interface.
GNU MP is designed to be as fast as possible, both for small operands and for
huge operands. The speed is achieved by using fullwords as the basic
arithmetic type, by using fast algorithms, by carefully optimized assembly
code for the most common inner loops for a lots of CPUs, and by a general
emphasis on speed (instead of simplicity or elegance).
The speed of GNU MP is believed to be faster than any other similar library.
The advantage for GNU MP increases with the operand sizes for certain
operations, since GNU MP in many cases has asymptotically faster algorithms.
GETTING STARTED
First, you have to configure and compiler GNU MP. Simply typing
./configure; make
will normally do a reasonable job, but will not give optimal library
execution speed. So unless you're very unpatient, please read the detailed
instructions in the file INSTALL or in gmp.texi.
Once you have compiled the library, you should write some small example, and
make sure you can compile them. A typical compilation command is this:
gcc -g your-file.c -I<gmp-source-dir> <gmp-bin-dir>libgmp.a -lm
If you have installed the library, you can simply do:
gcc -g your-file.c -lgmp -lm
The -lm is normally not needed, since only a few functions in GNU MP use the
math library.
Here is a sample program that declares 2 variables, initializes them as
required, and sets one of them from a signed integer, and the other from a
string of digits. It then prints the product of the two numbers in base 10.
integers, rational numbers, and floating point numbers. It has a rich set of
functions, and the functions have a regular interface.
#include <stdio.h>
#include "gmp.h"
GNU MP is designed to be as fast as possible, both for small operands and huge
operands. The speed is achieved by using fullwords as the basic arithmetic
type, by using fast algorithms, with carefully optimized assembly code for the
most common inner loops for lots of CPUs, and by a general emphasis on speed
(instead of simplicity or elegance).
main ()
{
mpz_t a, b, p;
GNU MP is believed to be faster than any other similar library. Its advantage
increases with operand sizes for certain operations, since GNU MP in many
cases has asymptotically faster algorithms.
mpz_init (a); /* initialize variables */
mpz_init (b);
mpz_init (p);
GNU MP is free software and may be freely copied on the terms contained in the
files COPYING.LIB and COPYING (most of GNU MP is under the former, some under
the latter).
mpz_set_si (a, 756839); /* assign variables */
mpz_set_str (b, "314159265358979323846", 0);
mpz_mul (p, a, b); /* generate product */
mpz_out_str (stdout, 10, p); /* print number without newline */
puts (""); /* print newline */
mpz_clear (a); /* clear out variables */
mpz_clear (b);
mpz_clear (p);
exit (0);
}
This might look tedious, with all initializing and clearing. Fortunately
some of these operations can be combined, and other operations can often be
avoided. The example above would be written differently by an experienced
GNU MP user:
#include <stdio.h>
#include "gmp.h"
main ()
{
mpz_t b, p;
mpz_init (p);
mpz_init_set_str (b, "314159265358979323846", 0);
mpz_mul_ui (p, b, 756839); /* generate product */
mpz_out_str (stdout, 10, p); /* print number without newline */
puts (""); /* print newline */
exit (0);
}
OVERVIEW OF GNU MP
There are five classes of functions in GNU MP.
1. Signed integer arithmetic functions, mpz_*. These functions are intended
1. Signed integer arithmetic functions (mpz). These functions are intended
to be easy to use, with their regular interface. The associated type is
`mpz_t'.
2. Rational arithmetic functions, mpq_*. For now, just a small set of
2. Rational arithmetic functions (mpq). For now, just a small set of
functions necessary for basic rational arithmetics. The associated type
is `mpq_t'.
3. Floating-point arithmetic functions, mpf_*. If the C type `double'
3. Floating-point arithmetic functions (mpf). If the C type `double'
doesn't give enough precision for your application, declare your
variables as `mpf_t' instead, set the precision to any number desired,
and call the functions in the mpf class for the arithmetic operations.
4. Positive-integer, hard-to-use, very low overhead functions are in the
mpn_* class. No memory management is performed. The caller must ensure
mpn class. No memory management is performed. The caller must ensure
enough space is available for the results. The set of functions is not
regular, nor is the calling interface. These functions accept input
arguments in the form of pairs consisting of a pointer to the least
significant word, and a integral size telling how many limbs (= words)
significant word, and an integral size telling how many limbs (= words)
the pointer points to.
Almost all calculations, in the entire package, are made by calling these
......@@ -128,10 +61,24 @@ printed. How to do that, as well how to build the library, is described in
the INSTALL file in this directory.
REPORTING BUGS
If you find a bug in the library, please make sure to tell us about it!
Report bugs and propose modifications and enhancements to
bug-gmp@prep.ai.mit.edu. What information is needed in a good bug report is
described in the manual.
You should first check the GNU MP web pages at http://www.swox.com/gmp/,
under "Status of the current release". There will be patches for all known
serious bugs there.
Report bugs to bug-gmp@gnu.org. What information is needed in a good bug
report is described in the manual. The same address can be used for
suggesting modifications and enhancements.