I was looking for how to work as big numbers in and found a blog that says it was possible to work using the library, wanted to know if it is part of the ANSI C standard?
I was looking for how to work as big numbers in and found a blog that says it was possible to work using the library, wanted to know if it is part of the ANSI C standard?
Standard libraries do not provide support for arithmetic operations with values greater than 64 bits.
Operations with large integers can be done using a GNU
library called gmplib .
Here is an example where the two arguments (large integers) passed to 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
Output:
12193263124676116335924401657049230176967230591384377380136092059011263526900
Checking: