gmp

Version:

6.2.0, 6.2.1

Category:

math

Cluster:

Vali

Author / Distributor

https://gmplib.org/

Description

GMP (GNU Multiple Precision Arithmetic Library) is a C library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers.

It is designed for speed, especially for very large numbers, and is used in many applications requiring high-precision computations including cryptography, number theory, and symbolic computation systems.

Key features:

  • Arbitrary-precision integer, rational, and float support

  • Highly optimized assembly for multiple architectures

  • Interfaces for C and C++

Documentation

GMP is a development library and does not provide command-line tools.
It is used by including headers and linking with the library in C/C++ projects.

Compilation example:

    gcc -I$GMP_INC -L$GMP_LIB -lgmp example.c -o example

Example usage in code:

    #include <gmp.h>
    mpz_t a, b, sum;
    mpz_init_set_str(a, "123456789123456789", 10);
    mpz_init_set_str(b, "987654321987654321", 10);
    mpz_init(sum);
    mpz_add(sum, a, b);
    gmp_printf("Sum is %Zd\n", sum);

Documentation: https://gmplib.org/manual/

Examples/Usage

  • Load the GMP module:

    $ module load math/GMP/6.2.0-GCCcore-10.2.0
    
  • Unload the GMP module:

    $ module unload math/GMP/6.2.0-GCCcore-10.2.0
    
  • Compile and run a sample program:

    gcc -I$EBROOTGMP/include -L$EBROOTGMP/lib -lgmp test_gmp.c -o test_gmp
    ./test_gmp
    

Installation

Source code is obtained from GMP