gmp

MinGW library converted to Windows library gives odd link in VC++6

I used the MinGW .a to Windows .lib transformation process as detailed in a thread on the gmp-discuss list, as below (acting against a library created with --disable-shared --enable-static.) cp libgmp.a gmp.a ranlib gmp.a mv gmp.a gmp.lib I now have a .lib file against which VC++6 seems to have no difficulty linking. What concerns me...

Adding floats with gmp gives "correct" results, sort of ...

In the code below I use mpf_add to add the string representation of two floating values. What I don't understand at this point is why 2.2 + 3.2 = 5.39999999999999999999999999999999999999. I would have thought that gmp was smart enough to give 5.4. What am I not comprehending about how gmp does floats? (BTW, when I first wrote this I w...

How does one calculate 2 ^ -18 using GMP?

I've just discovered, to my embarrassment, that feeding negative exponents to mpz_pow_ui doesn't work very well. ("The manual does say unsigned long, you know.") For the other mpz_pow functions, the manual uses concepts I don't understand. For example "base^exp mod mod" in the following: void mpz_powm (mpz_t rop, mpz_t base, mpz_t exp, ...

GMP can't cope with a leading "+"?

Consider the following code // BOGP.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "gmp-static\gmp.h" #include <stdlib.h> /* For _MAX_PATH definition */ #include <stdio.h> #include <malloc.h> #define F(x) mpf_t x; mpf_init( x ); int main(int argc, char* argv[]) { F(foo); char * b...

Lost precision on GMP mpf_add. Where have my digits gone?

I'm summing two negative floats: char * lhs = "-2234.6016114467412141"; char * rhs = "-4939600281397002.2812"; According to Perl, using bignum and Math::BigFloat, the answer is -4939600281399236.8828114467412141 However, according to GMP, using the code below, the answer is -4939600281399236.88281 Where have I gone wrong? What h...

How to detect mantissa precision overflow in GMP, before or after it happens?

The question I meant to ask concerned the mantissa, not the exponent, and has lots to do with the question I asked earlier in the week regarding "missing" digits on the sum of two negative floats. Given that the mantissa has a variable precision, how does one tell if one has overflowed the mantissa's current precision setting? Or, from ...

why would freeing calloc'ed memory crash my VC6 project?

Compare these two largely identical functions. In the first, the memory for buff is allocated using _alloca. This works fine. In the second, calloc and free are used instead of _alloca. This crashes. The weird thing is that I use the calloc/free technique in almost every other GMP wrapping function I have and they all work. Here they d...

Square root of bignum using GMP

I need to get the square root of a 210 digit number accurately, I thought GMP was the right tool for the job, what am I doing wrong? #include <stdlib.h> #include <stdio.h> #include "gmp.h" int main (int argc, char *argv[]) { mpz_t sq_me, sq_out, test; mpz_init(sq_me); mpz_init(sq_out); mpz_init(test); mpz_set_str (sq_me, argv...

Building GMP library with Visual Studio?

Is there an easy way to build the GMP (GNU Multiple Precision Arithmetic Library, http://gmplib.org) under Windows, using Visual Studio 2005? I tried to find information about building the library myself, but could not find anything that really helped me. I'm not very experienced with building libraries myself (I've managed to build boos...

Can one know how large a factorial would be before calculating it?

I'm using GMP to calculate very large factorials (e.g. 234234!). Is there any way of knowing, before one does the calculation, how many digits long the result will (or might) be? ...

Is this a bug in GMP 4.1.2 or is it something I'm doing wrong?

To this bit of code I pass the string "kellogs special k" and I get 1 which means that the string is an integer. What on earth am I doing wrong? Or is it a GMP problem? #define F(x) mpf_t (x); mpf_init( (x) ); long __stdcall FBIGISINTEGER(BSTR p1) { USES_CONVERSION; F(n1); LPSTR sNum1 = W2A( p1 ); mpf_set_str( n1, sNum1, 10 ); re...

Are integers in C assumed to be handled by a hardware spec or handled in software?

Are integers in C assumed to be handled by a hardware spec or handled in software? By integer, I am referring to the primitive "int" The underlying idea being that if integers in C are not hardware dependent would it be a violation of standard to have gcc implement different integer handlers. This way you could have your traditional 32...

In PHP, how do I generate a big pseudo-random number?

I'm looking for a way to generate a big random number with PHP, something like: mt_rand($lower, $upper); The closer I've seen is gmp_random() however it doesn't allow me to specify the lower and upper boundaries only the number of bits per limb (which I've no idea what it is). EDIT: Axsuuls answer seems to be pretty close to what I w...

Calculating roots with bc_math or GMP

I'm having trouble calculating roots of rather large numbers using bc_math, example: - pow(2, 2) // 4, power correct - pow(4, 0.5) // 2, square root correct - bcpow(2, 2) // 4, power correct - bcpow(4, 0.5) // 1, square root INCORRECT Does anybody knows how I can circumvent this? gmp_pow() also doesn't work. ...

Handling expressions in GMP

I introduced myself to the GMP library for high precision arithmetic recently. It seems easy enough to use but in my first program I am running into practical problems. How are expressions to be evaluated. For instance, if I have "1+8*z^2" and z is a mpz_t "large integer" variable, how am I to quickly evaluate this? (I have larger expres...

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 than the python (for the same cases that fit in long longs). Is there a better bignum im...

double free error with pointer to array of mpz_t

Hi, I'm currently learning libgmp and to that end I'm writing a small program which find prime factors. My program calls a function which fills an array with a varying amount of mpz_t integers, prime factors of a given number, which I need to return. I'm planning on setting the last element to NULL, so I know how many mpz_t integers the...

Gmpy documentation anywhere?

I installed gmpy-1.11rc1.win32-py2.6.exe, but can't figure out how to use it, I can see some exported functions like mpz, mpq, mpf, etc., but how do I call a function like mpz_probab_prime_p() in GNU MP C library? I looked at gmpy on Google Code, but still can't figure out. I couldn't find gmpy's documentation anywhere either. Thanks. ...

Using gmp 5 on CentOs 5.3

Hey, I'm using CentOS version 5.3 x86_64, Intel X5550 processor. I compiled gmp 5.0.0 on this system. When I try to run it, I'm getting the error :- error while loading shared libraries: libgmp.so.3: wrong ELF class : ELFCLASS64 which I can't understand since I'm working on a 64-bit system with a 64-bit isa. Any help would be welco...

Adding Compile Flags in Xcode

(I'm not sure if "flag" is the word I'm looking for, but I'll explain it.) I am trying to compile a program that uses the GMP big number library. But to be able to compile with GMP, I have to add -lgmp to the end of the command. For example, if I want to compile "program.c", I have to type gcc program.c -lgmp. This is easy from the comm...