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
10
votes
3 answers

Some questions about a single-instance array in typedef

I was perusing some code using arbitrary-length integers using the GNU Multi-Precision (GMP) library code. The type for a MP integer is mpz_t as defined in gmp.h header file. But, I've some questions about the lower-level definition of this…
pr1268
  • 1,176
  • 3
  • 9
  • 16
10
votes
1 answer

How to enable GMP in PHP on OS X?

Using OS X 10.11.1 (El Capitan) and PHP 5.5.29. I would like to add the GMP extension to my PHP, but I have no clue to do so. According to the PHP manual I'm supposed compile PHP with a --with-gmp=dir option. But I don't know how to compile PHP (I…
RocketNuts
  • 9,958
  • 11
  • 47
  • 88
9
votes
1 answer

PHP - GMP and floating point numbers?

The following code outputs 0, which isn't correct: $r = gmp_pow(gmp_init('-1.7976931348623157'), 308); echo gmp_strval($r); I was under the impression that the GMP library was capable of handling floating point numbers, or have I made a mistake in…
Matty
  • 33,203
  • 13
  • 65
  • 93
9
votes
3 answers

Why is one of these dynamic programming implementations of the Fibonacci sequence faster than the other?

I've been researching and benchmarking various Fibonacci algorithms recently for my own amusement and more or less by accident came up with an alternate implementation of the classic O(n) time and O(1) space dynamic programming…
9
votes
1 answer

Why BigFloat.to_s is not precise enough?

I am not sure if this is a bug. But I've been playing with big and I cant understand why this code works this way: https://carc.in/#/r/2w96 Code require "big" x = BigInt.new(1<<30) * (1<<30) * (1<<30) puts "BigInt: #{x}" x = BigFloat.new(1<<30) *…
Ihor Tsykalo
  • 133
  • 1
  • 4
9
votes
5 answers

Factor a large number efficiently with gmp

I need to get all the prime factors of large numbers that can easily get to 1k bits. The numbers are practically random so it shouldn't be hard. How do I do it efficiently? I use C++ with GMP library. EDIT: I guess you all misunderstood me. What I…
Daniel
  • 30,896
  • 18
  • 85
  • 139
9
votes
2 answers

How to serialize the GMP mpf type?

It seems that GMP provides only string serialization of the mpf (floating point) type: mpf_get_str(), mpf_class::get_str() The mpz (integer) type has an additional interface for raw bytes:…
jrr
  • 1,877
  • 19
  • 29
9
votes
3 answers

Does GMPY2 (or GMP) have a pow() function?

GMPY2 (or GMP) has a powmod function but I can't find anything for regular exponentiation aside from python's native pow. Does a function like this exist for mpz integers?
qwr
  • 9,525
  • 5
  • 58
  • 102
9
votes
5 answers

Overflow handling in GMP pow

(I am only an indirect user of the GMP-library primarily through swi-prolog and yap. But I am very much interested in fixing this problem.) When performing exponentiations with ridiculously large values, the host-systems or GMP are no longer able to…
false
  • 10,264
  • 13
  • 101
  • 209
8
votes
7 answers

GCC cant find GMP, MPFR and MPC libraries

I am trying to cross-compile GCC on Mac OS 10.5.7. I used this command to configure GCC after installing GMP, MPFR, and MPC: ../gcc-4.5.0/configure --target=$i586-elf --prefix=/usr/local/cross \ --disable-nls \ …
None
  • 3,875
  • 7
  • 43
  • 67
8
votes
1 answer

Big number arithmetic using LLVM (from Haskell)

An answer to my previous question indicated that Haskell represents plusWord2# as llvm.uadd.with.overflow. I'm looking to do long addition with carry, like how the x86 ADC instruction works. This instruction not only adds it's two arguments, but…
Clinton
  • 22,361
  • 15
  • 67
  • 163
8
votes
0 answers

GMP & MPFR not found by cmake, but are installed

I'm trying to compile the plll library which require boost, GMP and MPFR on mac os X 10.11. I've installed boost, GMP and MPFR by homebrew, then i've launched cmake in a dir build in plll, but I get that error : By not providing "FindMPFR.cmake"…
user70925
  • 263
  • 2
  • 5
8
votes
1 answer

Using GHC, cabal with GMP installed in user-space

I have been trying to install Haskell Platform and cabal-install installed on Linux in user-space on a system that doesn't have the GNU Multi-Precision package (GMP) installed. I managed to get GHC-6.12.1 installed and GHCi working by setting up…
chrisdornan
  • 217
  • 3
  • 9
8
votes
4 answers

Error in linking gmp while compiling cpabe package from its source code

I ended up spending several hours for compiling cpabe package from its source code in Ubuntu 12.10, with gmp and pbc dependencies. The following error message seemed to be the problem of many people in the Web(even for compiling other packages that…
happyMar
  • 113
  • 1
  • 6
8
votes
1 answer

C++ - MPIR: mpz_t to std::string?

How do we convert mpz_t to std::string? mpz_t Var; // Var = 5000 mpz_init_set_ui( Var, 5000 ); std::string Str = ""; // Convert Var to std::string? mpz_clear( Var );
Robert Wish
  • 155
  • 2
  • 9
1 2
3
68 69