Detailed descriptions of the IMath API can be found in the 35K file that accompanies the IMath distribution. However, the following is a brief synopsis of how to get started with some simple tasks.
To do basic integer arithmetic, you must declare variables of type mpz_t in your program, and call the functions defined in imath.h to operate on them. Here is a simple example that reads one base-10 integer from the command line, multiplies it by another (fixed) value, and prints the result to the standard output in base-10 notation:
#include <stdio.h>
#include <stdlib.h>
#include "imath.h"
int main(int argc, char *argv[])
{
mpz_t a, b;
char *buf;
int len;
if(argc < 2) {
fprintf(stderr, "Usage: testprogram <integer>\n");
return 1;
}
/* Initialize a new zero-valued mpz_t structure */
mp_int_init(&a);
/* Initialize a new mpz_t with a small integer value */
mp_int_init_value(&b, 25101);
/* Read a string value in the specified radix */
mp_int_read_string(&a, 10, argv[1]);
/* Multiply the two together... */
mp_int_mul(&a, &b, &a);
/* Print out the result */
len = mp_int_string_len(&a, 10);
buf = calloc(len, sizeof(*buf));
mp_int_to_string(&a, 10, buf, len);
printf("result = %s\n", buf);
free(buf);
/* Release memory occupied by mpz_t structures when finished */
mp_int_clear(&b);
mp_int_clear(&a);
return 0;
}
big
This simple example program does not do any error checking, but all the IMath API functions return an mp_result value which can be used to detect various problems like range errors, running out of memory, and undefined results.
The IMath API also supports operations on arbitrary precision rational numbers. The functions for creating and manipulating rational values (type mpq_t) are defined in imrat.h, so that you need only include them in your project if you wish to.
Fotoleinwand Billig. book of ra. football live