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

Annotation of OpenXM_contrib/gmp/INSTALL, Revision 1.1.1.3

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

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