source: trunk/third/gmp/INSTALL @ 18191

Revision 18191, 5.0 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18190, which included commits to RCS files with non-trunk default branches.
Line 
1Copyright 1996, 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
2
3This file is part of the GNU MP Library.
4
5The GNU MP Library is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or (at your
8option) any later version.
9
10The GNU MP Library is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
13License for more details.
14
15You should have received a copy of the GNU Lesser General Public License
16along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
17the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1802111-1307, USA.
19
20
21
22
23
24                          INSTALLING GNU MP
25                          =================
26
27
28These instructions are only for the impatient.  Others should read the install
29instructions in gmp.info.  Use
30
31        info -f ./gmp.info
32
33or in emacs
34
35        C-u C-h i gmp.info
36
37
38Here are some brief instructions on how to install GMP, and some examples to
39help you get started using it.  First you need to compile.  Since you're
40impatient, try this
41
42        ./configure
43        make
44
45If that fails, or you care about the performance of GMP, you need to read the
46full instructions in the chapter "Installing GMP" in the manual.
47
48Optionally, you can install with the following.  This will be to /usr/local by
49default, and you'll probably need to be "root" to be able to write there.
50
51        make install
52
53Next, try some small test programs, for example the ones below.
54
55In GMP programs, all variables need to be initialized before they are
56assigned, and cleared out before program flow leaves the scope in which they
57were declared.  Here is an example program that reads two numbers from the
58command line, multiplies them, and prints the result to stdout.
59
60
61    #include <stdio.h>
62    #include <gmp.h>         /* All GMP programs need to include gmp.h */
63
64    main (int argc, char **argv)
65    {
66      mpz_t a, b, p;
67
68      if (argc != 3)
69        {
70          printf ("Usage: %s <number> <number>\n", argv[0]);
71          exit (1);
72        }
73
74      /* Initialize variables */
75      mpz_init (a);
76      mpz_init (b);
77      mpz_init (p);
78
79      /* Assign a and b from base 10 strings in argv */
80      mpz_set_str (a, argv[1], 10);
81      mpz_set_str (b, argv[2], 10);
82
83      /* Multiply a and b and put the result in p */
84      mpz_mul (p, a, b);
85
86      /* Print p in decimal */
87      gmp_printf ("%Zd\n", p);
88
89      /* Clear out variables */
90      mpz_clear (a);
91      mpz_clear (b);
92      mpz_clear (p);
93      exit (0);
94    }
95
96
97This might look tedious, with all the initializing and clearing.  Fortunately
98some of these operations can be combined, and other operations can often be
99avoided.  An experienced GMP user might write:
100
101
102    #include <stdio.h>
103    #include <gmp.h>
104
105    main (int argc, char **argv)
106    {
107      mpz_t a, b, p;
108
109      if (argc != 3)
110        {
111          printf ("Usage: %s <number> <number>\n", argv[0]);
112          exit (1);
113        }
114
115      /* Initialize and assign a and b from base 10 strings in argv */
116      mpz_init_set_str (a, argv[1], 10);
117      mpz_init_set_str (b, argv[2], 10);
118      /* Initialize p */
119      mpz_init (p);
120
121      /* Multiply a and b and put the result in p */
122      mpz_mul (p, a, b);
123
124      /* Print p in decimal */
125      gmp_printf ("%Zd\n", p);
126
127      /* Since we're about to exit, no need to clear out variables */
128      exit (0);
129    }
130
131
132Now you have to compile your test program, and link it with the GMP library.
133Assuming your working directory is still the gmp build directory, and your
134source file is called example.c, enter:
135
136        gcc -g -I. example.c .libs/libgmp.a
137
138After installing, the command becomes: "gcc -g example.c -lgmp".  Also, GMP is
139libtool based so you can use that to link if you want.
140
141Now try to run the example:
142
143        ./a.out 98365871231256752134 319378318340103345227
144        31415926535897932384618573336104570964418
145
146The functions used here all operate on signed integers, and have names
147starting with "mpz_".  There are many more such functions than used in these
148examples.  See the chapter "Integer Functions" in the manual for a complete
149list.
150
151There are two other main classes of functions in GMP.  They operate on
152rational numbers and floating-point numbers, respectively.  The chapters
153"Rational Number Functions", and "Floating-point Functions" document these
154classes.
155
156To run a set of tests, do "make check".  This will take a while.
157
158To create the printable documentation from the texinfo source, type "make
159gmp.dvi" or "make gmp.ps".  This requires various "tex" commands.
160
161If you decide to use GMP, it is a good idea you at least read the chapter "GMP
162Basics" in the manual.
163
164Some known build problems are noted in the "Installing GMP" chapter of
165the manual.  Please report other problems to bug-gmp@gnu.org.
166
167
168
169----------------
170Local variables:
171mode: text
172fill-column: 78
173End:
Note: See TracBrowser for help on using the repository browser.