-
Notifications
You must be signed in to change notification settings - Fork 1
/
gmpwrap.c
44 lines (37 loc) · 866 Bytes
/
gmpwrap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* gmp-wrap.c
* 13 July 2000
* wrapper for GMP functions similar to mp.h
*/
#include <stdio.h>
#include <stdlib.h>
/* atoi() */
#include <limits.h>
/* INT_MAX, INT_MIN */
#include "gmp.h"
#include "gmpwrap.h"
void greduce(mpz_t a, mpz_t b)
{
mpz_t tmp;
mpz_init(tmp);
mpz_gcd(tmp, a, b);
mpz_divexact(a, a, tmp);
mpz_divexact(b, b, tmp);
mpz_clear(tmp);
}
int gmptoi(mpz_t a, int *result, int bcomplain)
{
char smp [MAXGMPCHARS]; /* string to print mp into */
gmptoa(a, smp);
*result = atoi(smp);
if (*result == INT_MAX || *result == INT_MIN)
{
if (bcomplain)
{
printf("Warning: Long integer %s ", smp);
printf("overflown, replaced by %d\n", *result);
}
return 1;
}
else
return 0;
}