summaryrefslogtreecommitdiff
path: root/INSTALL
blob: 5bafaeee870ad48750121f749560a0492b32ae8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
INSTALLING GMP
==============

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.

Here are short instructions how to install MP, and some examples that help you
get started using MP.

First, you need to compile, and optionally install, MP.  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.

Next, you need to try some small test programs, for example the ones below.

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 */

    main (int argc, char **argv)
    {
      mpz_t a, b, p;

      /* Initialize variables */
      mpz_init (a);
      mpz_init (b);
      mpz_init (p);

      /* Assign a and b from base 10 strings in argv */
      mpz_set_str (a, argv[1], 10);
      mpz_set_str (b, argv[2], 10);

      /* Multiply a and b and put the result in p */
      mpz_mul (p, a, b);

      /* Print p in base 10 */
      mpz_out_str (stdout, 10, p);
      fputc ('\n', stdout);

      /* Clear out variables */
      mpz_clear (a);
      mpz_clear (b);
      mpz_clear (p);
      exit (0);
    }


In practice, that example would be written like this instead:

    #include <stdio.h>
    #include <gmp.h>

    main (int argc, char **argv)
    {
      mpz_t a, b, p;

      /* 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);
      /* Initialize p */
      mpz_init (p);

      /* Multiply a and b and put the result in p */
      mpz_mul (p, a, b);

      /* Print p in base 10 */
      mpz_out_str (stdout, 10, p);
      fputc ('\n', stdout);

      /* Since we're about to exit, no need to clear out variables */
      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,
and that your source file is called example.c, enter:

	gcc -g -I. example.c .libs/libgmp.a


Now try to run the example:

	./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.

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.

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
gmp.dvi" or "make gmp.ps".  This requires various "tex" commands.

To install the library, do "make install" (you can then 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
Basics" in the manual.

Some known build problems are noted in the "Installing MP" chapter of
the manual.  Please report other problems to bug-gmp@gnu.org.