| version 1.1.1.1, 2000/01/10 15:35:21 |
version 1.1.1.2, 2000/09/09 14:12:13 |
|
|
| INSTALLING GMP |
|
| ============== |
|
| |
|
| |
INSTALLING GNU MP |
| |
================= |
| |
|
| |
|
| These instructions are only for the impatient. Others should read the install |
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 |
instructions in the manual, gmp.info. Use |
| don't have info, use type "C-h i g (gmp.info)Top" in emacs. |
|
| |
|
| Here are short instructions how to install MP, and some examples that help you |
info -f ./gmp.info |
| get started using MP. |
|
| |
|
| First, you need to compile, and optionally install, MP. Since you're |
or in emacs |
| |
|
| |
C-u C-h i gmp.info |
| |
|
| |
|
| |
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: |
impatient, try this: |
| |
|
| ./configure; make |
./configure; make |
| |
|
| If that fails, or you care about the performance of MP, you need to read the |
If that fails, or you care about the performance of GMP, you need to read the |
| full instructions in the chapter "Installing MP", in the manual. |
full instructions in the chapter "Installing GMP", in the manual. |
| |
|
| Next, you need to try some small test programs, for example the ones below. |
Next, try some small test programs, for example the ones below. |
| |
|
| In MP programs, all variables need to be initialized before they are assigned, |
In GMP programs, all variables need to be initialized before they are |
| and cleared out before program flow leaves the scope in which it was declared. |
assigned, and cleared out before program flow leaves the scope in which they |
| Here is an example of a program that reads two numbers from the command line, |
were declared. Here is an example program that reads two numbers from the |
| multiplies them, and prints the result to stdout. |
command line, multiplies them, and prints the result to stdout. |
| |
|
| |
|
| #include <stdio.h> |
#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) |
main (int argc, char **argv) |
| { |
{ |
| mpz_t a, b, p; |
mpz_t a, b, p; |
| |
|
| |
if (argc != 3) |
| |
{ printf ("Usage: %s <number> <number>\n", argv[0]); exit (1); } |
| |
|
| /* Initialize variables */ |
/* Initialize variables */ |
| mpz_init (a); |
mpz_init (a); |
| mpz_init (b); |
mpz_init (b); |
| Line 54 multiplies them, and prints the result to stdout. |
|
| Line 66 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 <stdio.h> |
| #include <gmp.h> |
#include <gmp.h> |
| |
|
| Line 63 In practice, that example would be written like this i |
|
| Line 78 In practice, that example would be written like this i |
|
| { |
{ |
| mpz_t a, b, p; |
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 */ |
/* Initialize and assign a and b from base 10 strings in argv */ |
| mpz_init_set_str (a, argv[1], 10); |
mpz_init_set_str (a, argv[1], 10); |
| mpz_init_set_str (b, argv[2], 10); |
mpz_init_set_str (b, argv[2], 10); |
| Line 80 In practice, that example would be written like this i |
|
| Line 98 In practice, that example would be written like this i |
|
| exit (0); |
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: |
Now try to run the example: |
| |
|
| a.out 98365871231256752134 319378318340103345227 |
./a.out 98365871231256752134 319378318340103345227 |
| 31415926535897932384618573336104570964418 |
31415926535897932384618573336104570964418 |
| |
|
| The functions used here all operate on the domain of signed integers. |
The functions used here all operate on signed integers, and have names |
| Functions operating on that domain have names starting with "mpz_". There are |
starting with "mpz_". There are many more such functions than used in these |
| many more such functions than used in these examples. See the chapter |
examples. See the chapter "Integer Functions" in the manual, for a complete |
| "Integer Functions" in the manual, for a complete list. |
list. |
| |
|
| There are two other main classes of functions in MP. They operate on rational |
There are two other main classes of functions in GMP. They operate on |
| numbers and floating-point numbers, respectively. The chapters "Rational |
rational numbers and floating-point numbers, respectively. The chapters |
| Number Functions", and "Floating-point Functions" documents these classes. |
"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 run a set of tests, do "make check". This will take a while. |
| |
|
| To create the printable documentation from the texinfo source, type "make |
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. |
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. |
Local variables: |
| |
mode: text |
| The system compiler on NeXT is a massacred and old gcc, even if the |
fill-column: 78 |
| compiler calls itself cc. This compiler cannot be used to build GMP. You |
End: |
| 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 "" |
|