GNU Multiple Precision (GMP) Arithmetic Library for Arduino.
Port of the mini-gmp library with support for arbitrary-precision integers and rational numbers. No support for floats.
Currently based on GMP v6.2.0.
Compared to vanilla mini-gmp, this library has the following modifications:
- In case of error, no error is printed to stderr before aborting
- The internal limb type defaults to
unsigned int(16 bit) instead ofunsigned long(32 bit), since AVR microcontrollers do not natively support 32-bit multiplication.
You can install this library via the built-in library manager in your Arduino IDE (Sketch > Include Library > Manage Libraries...), searching for gmp-ino and clicking "Install".
Sample usage:
#include <gmp-ino.h>
mpz_t counter;
void setup() {
mpz_init(counter);
}
void loop() {
mpz_add_ui(counter, counter, 1); // equivalent to `counter++`
}Important things to keep in mind:
- always call
mp*_initbefore using a variable for the first time - always call
mp*_clearwhen the contents of a variable are not needed anymore (if you don't, you will quickly exhaust the memory as memory used by the variables is not freed until the call tomp*_clear) - mini-gmp uses
malloc/realloc/freeto allocate memory for the arbitrary-precision numbers - any internal error during any call (e.g. division by 0, invalid arguments, memory exhausted) will hang your program: validate the arguments before performing calls
- GMP website
- GMP documentation - note that mini-gmp supports only a subset of the full GMP library
- mini-gmp
2020 Carlo Alberto Ferraris.
gmp-ino is licensed under the GNU LGPL v3.
GMP is dual licensed under the GNU GPL v2 or the GNU LGPL v3.