Welcome to the GMP Native Interface for .NET Library |
The GMP Native Interface for .NET Library exposes to .NET (through P-Invoke and .NET types) all of the functionality of the GNU MP Library (version 6.1.2). It automatically loads at runtime the 32-bit or 64-bit GNU MP library that matches the current CPU architecture, thus allowing building Visual Studio Projects for AnyCPU, x86, or x64. It is based on the GNU MP "fat" build which automatically detects the current CPU type, and selects any available assembly language code optimization for that CPU, thus providing optimal performance.
The gmp_lib class has a static method for each one of the GNU MP functions. Other types are defined to mimic struct's and typedef's of the GNU MP and C libraries, as well as C language constructs such as char * and void *.
The GMP Native Interface for .NET Library relies on pre-built 32-bit and 64-bit versions of the GNU MP Library. Instructions for building the GNU MP Library on Windows are given below.
For convenience, this help file has been created from the GNU MP manual version 6.1.2. It shows with examples how each GNU MP function is called in .NET. For an introduction to GNU MP, refer to the GNU MP Manual.
The table below shows how each C type maps to .NET. Note that the mp_limb_t and size_t C types map to the CPU word, i.e., 32 or 64 bits. In particular, because mp_limb_t is the type of the integers that make up multi-precision numbers, matching the CPU word size ensures maximum performance. Unless you intend to use low-level (mpn) functions, you do not need to take into account the CPU word size, and can build for the "Any CPU" platform.
C Types | .NET Types |
---|---|
short | Int16 |
int | Int32 |
long | Int32 |
long long | Int64 |
UInt32 | |
Int32 | |
Int32 | |
UInt32 (on 32-bit CPU) / UInt64 (on 64-bit CPU) | |
UInt32 (on 32-bit CPU) / UInt64 (on 64-bit CPU) |
Install MSYS2
Get the latest version from...
Install yasm
Install GNU MP
Build GNU MP