Questions tagged [gmp]

The GNU Multiple-Precision Library (GMP) is a mature, free library for arbitrary-precision arithmetic with support for big signed integers, rational numbers, and floating point numbers. The basic interface is for C but wrappers exist for other languages including Ada, C++, C#, OCaml, Perl, PHP, and Python. It is distributed under the GNU LGPL and is used for cryptography applications and in computer algebra systems such as Mathematica and Maple.

GMP, or GNU Multiple Precision Arithmetic Library, is a library allowing for arbitrary precision arithmetic. This means that calculations using the libraries internal variables are not limited to ordinary constraints of bit-level precision that many languages inherently possess.

It can support multiple different data types including floating-point numbers, signed integers and rational numbers. It is primarily used in areas related to cryptography, and is also heavily used in numerical research, other types of security applications and computational algebra.

Full words are used as the intrinsic data type, and logic is used to select separate algorithms depending upon the operand size for efficiency purposes. Critical parts of the library utilize Assembly code and is specialized for different processing units to further increase efficiency.

GMP is designed to run on systems running Unix derivates including Linux and Solaris, but may also work on 32-bit and 64-bit Windows machines.

The manual and information to get started using GMP are located here :

https://gmplib.org/manual/

1024 questions
5
votes
2 answers

GMP convert mpz to mpf

I am using GMP, and I want to be able to quickly convert an mpz to an mpf. I looked through the library and couldn't find much. The best thing I could think of was this: mpz_t x; /* Insert code here that assigns some value to x */ char…
Michael Dickens
  • 1,454
  • 4
  • 18
  • 26
5
votes
0 answers

Are there any recent GMP Windows binary distributions?

I'm looking for a recent (preferably up-to-date to the latest version) repository of binary builds of GMP for Windows. I've only been able to find horribly outdated (+5 years) builds so far. I can't compile GMP myself - the compilation needs too…
orlp
  • 112,504
  • 36
  • 218
  • 315
5
votes
3 answers

Bignum implementation that has efficient addition of small integers

I have been using python's native bignums for an algorithm and decided to try and speed it up by converting it to C++. When I used long longs, the C++ was about 100x faster than the python, but when I used GMP bindings in C++, it was only 10x faster…
sligocki
  • 6,246
  • 5
  • 38
  • 47
5
votes
4 answers

Fast primality test with 100% certainty?

I'm using GMP (with MPIR) for arbitrary size datatypes. I also use its primality test function, which uses Miller-Rabin method, but it is not accurate. This is what I want to fix. I was able to confirm that the number 18446744073709551253 is a prime…
Rookie
  • 4,064
  • 6
  • 54
  • 86
5
votes
1 answer

link cuda with gmp

I am trying to use cuda with the GNU multiple precision library (gmp). When I add gmp instructions like mpf_init() to my device code I get this compiler error: tlgmp.cu(37): error: calling a host function("__ gmpf_init") from a __ device__ /__…
5
votes
2 answers

flexible mpz_t array in struct

I have a struct like this: typedef struct{ size_t length; // length of the array size_t numbits; // number of bits allocated per val in vals mpz_t vals[]; // flexible array to hold some number of mpz_t array } CoolArray; Ok, so it's a…
Broseph
  • 1,655
  • 1
  • 18
  • 38
5
votes
2 answers

Installing GMP on MacOS X with Xcode

I'm trying to use the GMP library in my C and C++ programs. I do code using the Xcode. I followed the instructions to install the GMP on my machine and I end up with a folder "~/usr/local/gmp-5.0.5" which contains the gmp.h file. How can I make my…
user1483799
  • 409
  • 4
  • 8
  • 17
5
votes
1 answer

GMP gmp_printf()

I've just started messing with GMP and I can't seem to get numbers to print properly. Here is what I'm trying: #include #include #include "gmp.h" int main(){ mpz_t n; mpz_init (n); mpz_set_ui(n, 2); gmp_printf("attempt…
Zevan
  • 10,097
  • 3
  • 31
  • 48
5
votes
1 answer

Linking objects and static libraries

I am having a hard time figuring out what flags to pass to g++ when performing linking. Basically, I compile some code with these "standard" flags: CXXFLAGS = -Wall -Wextra -Wconversion -pedantic -std=c++0x -O2 and, afterwards, I merge the produced…
Mihai Todor
  • 8,014
  • 9
  • 49
  • 86
5
votes
4 answers

Installed gmp but can't see it

To compile my own gcc, I require gmp. Therefore, I downloaded a tarball of gmp, and installed it by the usual steps of configure, make and make install. However, afterwards, I can't see any gmp in my system by typing 'which gmp'. So my question is…
MetallicPriest
  • 29,191
  • 52
  • 200
  • 356
4
votes
1 answer

Using GMP for Cryptography: how to get random numbers?

The documentation for GMP seems to list only the following algorithms for random number generation: gmp_randinit_mt, the Mersenne Twister; gmp_randinit_lc_2exp and gmp_randinit_lc_2exp_size, linear congruential. There is also gmp_randinit_default,…
Jay
  • 9,585
  • 6
  • 49
  • 72
4
votes
1 answer

C++ - GMP pow() function

I am trying to do pow(2,500) in C++. But I think long long is not enough. Someone told me I can use gmp.h. But how do I do a pow(2,500) in gmp?
JJ Liu
  • 1,351
  • 8
  • 20
  • 36
4
votes
1 answer

R gmp package installation fails; configure: error: Header file gmp.h not found

When trying to install the R gmp package, the installation fails because of the following error: configure: error: Header file gmp.h not found the whole log: > installing *source* package 'gmp' ... > package 'gmp' successfully unpacked and MD5 sums…
BlS
  • 55
  • 4
4
votes
2 answers

GMP detect float exponent overflow when initializing

I am currently programming on 64-bit Fedora 36, and I realized that GMP floating point numbers have limitations on the exponent size: https://gmplib.org/manual/Floating_002dpoint-Functions The exponent of each float has fixed precision, one machine…
Eric Stdlib
  • 1,292
  • 1
  • 18
  • 32
4
votes
1 answer

CMake Could NOT find GMP

I am trying to cross-compile CVC4, but GMP could not be found. I use the following guide for the installation: http://cvc4.cs.stanford.edu/wiki/Developer%27s_Guide When I run ./configure.sh production I get the following error: CMake Error at…
Steve2Fish
  • 187
  • 4
  • 15