gmp

Arbitrary-precision random numbers in C: generation for Monte Carlo simulation without atmospheric noise

I know that there are other questions similar to this one, however the following question pertains to arbitrary-precision random number generation in C for use in Monte Carlo simulation. How can we generate good quality arbitrary-precision random numbers in C, when atmospheric noise isn't always available, without relying on disk i/o or...

Extremely big integer multiplication and addition

Greetings, I need to multiply two extremely long integer values stored in a text file (exported via GMP (MPIR, to be exact), so they can be any in any base). Now, I would usually just import these integers via the mpz_inp_str() function and perform the multiplication in RAM, however, these values are so long that I can't really load the...

Exit code 3 (not my return value, looking for source)

Greetings, my program exits with the code 3. No error messages, no exceptions, and the exit is not initiated by my code. The problem occurs when I am trying to read extremely long integer values from a text file (the text file is present and correctly opened, with successful prior reading). I am using very large amounts of memory (...

return type while using GMP.h header file

While i m using gmp.h header file. i need a fuction which takes inputs of type mpz_t and return mpz_t type too. I m very beginner of using gmp.h So, Here is snaps follows of my approached code.... mpz_t sum_upto(mpz_t max) { mpz_t sum; mpz_init(sum); mpz_init(result); for(int i=0;i<=max-1;i++) ...

How to implement long division for enormous numbers (bignums)

Hi, I'm trying to implement long division for bignums. I can't use a library like GMP unfortunately due to the limitations of embedded programming. Besides, i want the intellectual exercise of learning how to implement it. So far i've got addition and multiplication done using any-length arrays of bytes (so each byte is like a base-256 d...

How does GMP stores its integers, on an arbitrary number of bytes ?

2^64 is still far from the "infinity" my ram/hard drive can handle... First I wonder how GMP works with memory/processor since it does some kind of shady optimisations... I was also wondering if there is a way of storing an integer (unsigned, it's easier) on an arbitrary number of bytes. For example, on 50 bytes, I would have a cap of ...

Using GMP on windows

I am trying to use GMP in a C++ program on windows, and I compiled it successfully with Cygwin, and I get an .a file, which is linux's version of a .lib file. Is there a way I can use this with the Visual C++ compiler, or is there a way to compile GMP for windows to produce a .lib file? ...

In GMP, will passing a multiple-precision type as both a return argument and an operand argument work?

I have a problem in which I need to be prepared to explore a larger range of numbers than an unsized long long can represent (the range being represented by 3^(n*n) ). I have been advised by this community to use GMP for multiple-precision numbers. Since I need to iterate through the range one number at a time, I need a way to increment ...

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: mpz_out_raw() http://gmplib.org/manual/Function-Index.html Am I missing something? Does anyone know of another library that can serialize GMP flo...

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 \ --enable-languages=c,c++,fortran,java,objc,obj-c++,treelang,ada \ --without-headers --with-libiconv-prefix=/opt/loc...

avoiding abort in libgmp

I have some code that uses libgmp. At some point the user may request a factorial of a very large number. Unfortunately, this results in libgmp raising an abort signal. For example the following code: #include <cmath> #include <gmp.h> #include <iostream> int main() { mpz_t result; mpz_init(result); mpz_fac_ui(result, 209...

Help needed with math/bignum challenge

I'm struggling with the following bit of code(/challenge) and I was wondering what would be the best way to solve it. Pseudo(-like) code If I understand the code correctly it does: var val = 1 foreach (char in firstargument): val = val * ((ascii)char + 27137) if (val == 9215629587130840783880821452128359619700556749382698126651526...

Building GMP under MinGW - makefile problems

Downloaded and installed latest MinGW yesterday, and GMP 4.3.2 $ ./configure ran just fine. On running make check, The first problem was $ make check makefile:15: *** missing separator. Stop. OK, so, I put the TAB char at the beginning of line 15. Next problem is $ make check makefile:15: *** commands commence before first targe...

Problem using GMP with Eclipse C++ (CDT Helios)

I would like to compile my code in CDT: #include <iostream> #include <gmpxx.h> using namespace std; int main (void) { mpz_class a, b, c; a = 1234; b = "-5678"; c = a+b; cout << "sum is " << c << "\n"; cout << "absolute value is " << abs(c) << "\n"; cin >> a; return 0; } When I compiled, there were som...

How to find the greatest power of 2 dividing a number using GMP?

According to the GMP documentation here: Function: unsigned long int mpz_remove (mpz_t rop, mpz_t op, mpz_t f) Remove all occurrences of the factor f from op and store the result in rop. The return value is how many such occurrences were removed. So the mpz_remove function should be able to be used to answer the titled...

GMP and smart pointers

Hello. I'm working with gnump and have a function that must return mpz_t. So I have to use raw pointers to return a value. I allocate space with new for pointer and send it as a parameter in my function. I think it is better to use smart pointers. But I didn't work with them before. I read the manual but still can't understand how to ...