isl_aff_div: handle NaN input
[isl.git] / isl_gmp.c
blob2dbce62ef95a83e7662457b8a329bed408a99410
1 #include <stdio.h>
2 /*
3 * Copyright 2008-2009 Katholieke Universiteit Leuven
5 * Use of this software is governed by the MIT license
7 * Written by Sven Verdoolaege, K.U.Leuven, Departement
8 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
9 */
11 #include <isl_int.h>
13 uint32_t isl_gmp_hash(mpz_t v, uint32_t hash)
15 int sa = v[0]._mp_size;
16 int abs_sa = sa < 0 ? -sa : sa;
17 unsigned char *data = (unsigned char *)v[0]._mp_d;
18 unsigned char *end = data + abs_sa * sizeof(v[0]._mp_d[0]);
20 if (sa < 0)
21 isl_hash_byte(hash, 0xFF);
22 for (; data < end; ++data)
23 isl_hash_byte(hash, *data);
24 return hash;
27 /* This function tries to produce outputs that do not depend on
28 * the version of GMP that is being used.
30 * In particular, when computing the extended gcd of -1 and 9,
31 * some versions will produce
33 * 1 = -1 * -1 + 0 * 9
35 * while other versions will produce
37 * 1 = 8 * -1 + 1 * 9
39 * If configure detects that we are in the former case, then
40 * mpz_gcdext will be called directly. Otherwise, this function
41 * is called and then we try to mimic the behavior of the other versions.
43 void isl_gmp_gcdext(mpz_t G, mpz_t S, mpz_t T, mpz_t A, mpz_t B)
45 if (mpz_divisible_p(B, A)) {
46 mpz_set_si(S, mpz_sgn(A));
47 mpz_set_si(T, 0);
48 mpz_abs(G, A);
49 return;
51 if (mpz_divisible_p(A, B)) {
52 mpz_set_si(S, 0);
53 mpz_set_si(T, mpz_sgn(B));
54 mpz_abs(G, B);
55 return;
57 mpz_gcdext(G, S, T, A, B);