[BACK]Return to INSTALL CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp

Annotation of OpenXM_contrib/gmp/INSTALL, Revision 1.1.1.2

1.1.1.2 ! maekawa     1:
        !             2:                           INSTALLING GNU MP
        !             3:                           =================
        !             4:
1.1       maekawa     5:
                      6: These instructions are only for the impatient.  Others should read the install
1.1.1.2 ! maekawa     7: instructions in the manual, gmp.info.  Use
        !             8:
        !             9:        info -f ./gmp.info
        !            10:
        !            11: or in emacs
        !            12:
        !            13:        C-u C-h i gmp.info
        !            14:
1.1       maekawa    15:
1.1.1.2 ! maekawa    16: Here are some brief instructions on how to install GMP, and some examples to
        !            17: help you get started using GMP.
1.1       maekawa    18:
1.1.1.2 ! maekawa    19: First, you need to compile, and optionally install, GMP.  Since you're
1.1       maekawa    20: impatient, try this:
                     21:
                     22:        ./configure; make
                     23:
1.1.1.2 ! maekawa    24: If that fails, or you care about the performance of GMP, you need to read the
        !            25: full instructions in the chapter "Installing GMP", in the manual.
1.1       maekawa    26:
1.1.1.2 ! maekawa    27: Next, try some small test programs, for example the ones below.
        !            28:
        !            29: In GMP programs, all variables need to be initialized before they are
        !            30: assigned, and cleared out before program flow leaves the scope in which they
        !            31: were declared.  Here is an example program that reads two numbers from the
        !            32: command line, multiplies them, and prints the result to stdout.
1.1       maekawa    33:
                     34:
                     35:     #include <stdio.h>
1.1.1.2 ! maekawa    36:     #include <gmp.h>         /* All GMP programs need to include gmp.h */
1.1       maekawa    37:
                     38:     main (int argc, char **argv)
                     39:     {
                     40:       mpz_t a, b, p;
                     41:
1.1.1.2 ! maekawa    42:       if (argc != 3)
        !            43:         { printf ("Usage: %s <number> <number>\n", argv[0]); exit (1); }
        !            44:
1.1       maekawa    45:       /* Initialize variables */
                     46:       mpz_init (a);
                     47:       mpz_init (b);
                     48:       mpz_init (p);
                     49:
                     50:       /* Assign a and b from base 10 strings in argv */
                     51:       mpz_set_str (a, argv[1], 10);
                     52:       mpz_set_str (b, argv[2], 10);
                     53:
                     54:       /* Multiply a and b and put the result in p */
                     55:       mpz_mul (p, a, b);
                     56:
                     57:       /* Print p in base 10 */
                     58:       mpz_out_str (stdout, 10, p);
                     59:       fputc ('\n', stdout);
                     60:
                     61:       /* Clear out variables */
                     62:       mpz_clear (a);
                     63:       mpz_clear (b);
                     64:       mpz_clear (p);
                     65:       exit (0);
                     66:     }
                     67:
                     68:
1.1.1.2 ! maekawa    69: This might look tedious, with all the initializing and clearing.  Fortunately
        !            70: some of these operations can be combined, and other operations can often be
        !            71: avoided.  An experienced GMP user might write:
        !            72:
1.1       maekawa    73:
                     74:     #include <stdio.h>
                     75:     #include <gmp.h>
                     76:
                     77:     main (int argc, char **argv)
                     78:     {
                     79:       mpz_t a, b, p;
                     80:
1.1.1.2 ! maekawa    81:       if (argc != 3)
        !            82:         { printf ("Usage: %s <number> <number>\n", argv[0]); exit (1); }
        !            83:
1.1       maekawa    84:       /* Initialize and assign a and b from base 10 strings in argv */
                     85:       mpz_init_set_str (a, argv[1], 10);
                     86:       mpz_init_set_str (b, argv[2], 10);
                     87:       /* Initialize p */
                     88:       mpz_init (p);
                     89:
                     90:       /* Multiply a and b and put the result in p */
                     91:       mpz_mul (p, a, b);
                     92:
                     93:       /* Print p in base 10 */
                     94:       mpz_out_str (stdout, 10, p);
                     95:       fputc ('\n', stdout);
                     96:
                     97:       /* Since we're about to exit, no need to clear out variables */
                     98:       exit (0);
                     99:     }
                    100:
                    101:
1.1.1.2 ! maekawa   102: Now you have to compile your test program, and link it with the GMP library.
        !           103: Assuming your working directory is still the gmp source directory, and your
        !           104: source file is called example.c, enter:
        !           105:
        !           106:        gcc -g -I. example.c .libs/libgmp.a
1.1       maekawa   107:
1.1.1.2 ! maekawa   108: After installing, the command becomes: "gcc -g example.c -lgmp".  Also, GMP is
        !           109: libtool based so you can use that to link if you want.
1.1       maekawa   110:
                    111: Now try to run the example:
                    112:
1.1.1.2 ! maekawa   113:        ./a.out 98365871231256752134 319378318340103345227
1.1       maekawa   114:        31415926535897932384618573336104570964418
                    115:
1.1.1.2 ! maekawa   116: The functions used here all operate on signed integers, and have names
        !           117: starting with "mpz_".  There are many more such functions than used in these
        !           118: examples.  See the chapter "Integer Functions" in the manual, for a complete
        !           119: list.
        !           120:
        !           121: There are two other main classes of functions in GMP.  They operate on
        !           122: rational numbers and floating-point numbers, respectively.  The chapters
        !           123: "Rational Number Functions", and "Floating-point Functions" document these
        !           124: classes.
1.1       maekawa   125:
                    126: To run a set of tests, do "make check".  This will take a while.
                    127:
                    128: To create the printable documentation from the texinfo source, type "make
1.1.1.2 ! maekawa   129: gmp.dvi" or "make gmp.ps".  This requires various "tex" commands.
1.1       maekawa   130:
1.1.1.2 ! maekawa   131: To install the library, do "make install" (then you can use -lgmp instead of
        !           132: .libs/libgmp.a).
1.1       maekawa   133:
1.1.1.2 ! maekawa   134: If you decide to use GMP, it is a good idea you at least read the chapter "GMP
1.1       maekawa   135: Basics" in the manual.
                    136:
1.1.1.2 ! maekawa   137: Some known build problems are noted in the "Installing GMP" chapter of
        !           138: the manual.  Please report other problems to bug-gmp@gnu.org.
        !           139:
1.1       maekawa   140:
                    141:
1.1.1.2 ! maekawa   142: ----------------
        !           143: Local variables:
        !           144: mode: text
        !           145: fill-column: 78
        !           146: End:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>