1
I was looking for how to work as big numbers on and found a blog that talks that it was possible to work using the library, I wondered if it is part of the ANSI C standard ?
1
I was looking for how to work as big numbers on and found a blog that talks that it was possible to work using the library, I wondered if it is part of the ANSI C standard ?
2
Standard libraries do not provide support for arithmetic operations with values of more than 64 bits.
Operations with large integers can be done using a library from GNU
calling for gmplib.
Here is an example where the two arguments (large integers) passed to the main()
are multiplied and their result displayed on the screen:
#include <gmp.h>
#include <stdio.h>
#define MAX_BUF_LEN (128)
int main( int argc, char * argv[] )
{
char res[ MAX_BUF_LEN ];
mpz_t a, b, c;
mpz_init(a);
mpz_init(b);
mpz_init(c);
mpz_set_str( a, argv[1], 10 );
mpz_set_str( b, argv[2], 10 );
mpz_mul( c, a, b );
mpz_get_str( res, 10, c );
printf("%s\n", res );
mpz_clear(a);
mpz_clear(b);
mpz_clear(c);
return 0;
}
compiling:
$ gcc -lgmp -Wall bigintmul.c -o bigintmul
Testing:
$ ./bigintmul 1234567890123456789012345678901234567890 9876543219876543219876543219876543210
Exit:
12193263124676116335924401657049230176967230591384377380136092059011263526900
Checking:
Important the author check if the recommended lib license allows use where it needs. It would probably be good to mention also some alternative with MIT or BSD license.
Browser other questions tagged c
You are not signed in. Login or sign up in order to post.
No. It is installed somewhere recognized by the compiler as default, but does not belong to the standard language.
– Jefferson Quesado
Vixe, wanted to work with large numbers and this library had solved but, I won’t be able to use it, I would have another library that is standard to work with large numbers or a code that does this work
– rafael marques
standard library to work with large numbers? No no. All implementation of
BigNumber
orBigInteger
that I know uses a third-party library for such.– Jefferson Quesado
But libraries for this, not take one that does something else that happens to do something that you want, but is not her goal :)
– Maniero
Any specific ? Recommends some material to solve my problem ?
– rafael marques
Considering that Openssl has a license until it is convenient, and has for virtually any platform, it could probably continue using that same one. Now, if you use Openssl just for that, as @Maniero mentioned, a dedicated alternative might be more interesting. On the other hand, if the application uses Openssl, use what you already have.
– Bacco