10 #if SI_INTEGER_VARIANT == 2
17 static number nrzMult (number a, number
b,
const coeffs)
21 mpz_mul(erg, (mpz_ptr) a, (mpz_ptr)
b);
28 static number nrzLcm (number a,number
b,
const coeffs)
32 mpz_lcm(erg, (mpz_ptr) a, (mpz_ptr)
b);
40 static number nrzGcd (number a,number
b,
const coeffs)
44 mpz_gcd(erg, (mpz_ptr) a, (mpz_ptr)
b);
52 static number nrzExtGcd (number a, number
b, number *
s, number *t,
const coeffs)
60 mpz_gcdext(erg, bs, bt, (mpz_ptr) a, (mpz_ptr)
b);
66 static number nrzXExtGcd (number a, number
b, number *
s, number *t, number *u, number *
v,
const coeffs )
75 mpz_gcdext(erg, bs, bt, (mpz_ptr)a, (mpz_ptr)
b);
80 mpz_init_set(bu, (mpz_ptr)
b);
81 mpz_init_set(bv, (mpz_ptr) a);
83 assume(mpz_cmp_si(erg, 0));
97 static void nrzPower (number a,
int i, number *
result,
const coeffs)
101 mpz_pow_ui(erg, (mpz_ptr) a,
i);
111 mpz_init_set_si(erg,
i);
119 mpz_clear((mpz_ptr) *a);
125 static number nrzCopy(number a,
const coeffs)
129 mpz_init_set(erg, (mpz_ptr) a);
134 number nrzCopyMap(number a,
const coeffs ,
const coeffs dst)
136 return nrzCopy(a,dst);
142 mpz_ptr
p=(mpz_ptr)a;
144 if (
s==1)
s=(mpz_cmp_ui(
p,0)!=0);
152 static long nrzInt(number &
n,
const coeffs)
154 return mpz_get_si( (mpz_ptr)
n);
157 static number nrzAdd (number a, number
b,
const coeffs)
161 mpz_add(erg, (mpz_ptr) a, (mpz_ptr)
b);
165 static number nrzSub (number a, number
b,
const coeffs)
169 mpz_sub(erg, (mpz_ptr) a, (mpz_ptr)
b);
173 static number nrzGetUnit (number,
const coeffs r)
180 return 0 == mpz_cmpabs_ui((mpz_ptr) a, 1);
185 return 0 == mpz_cmpabs_ui((mpz_ptr) a, 0);
190 return (0 == mpz_cmp_ui((mpz_ptr) a, 1));
195 return (0 == mpz_cmp_si((mpz_ptr) a, -1));
200 return 0 == mpz_cmp((mpz_ptr) a, (mpz_ptr)
b);
205 return 0 < mpz_cmp((mpz_ptr) a, (mpz_ptr)
b);
215 return mpz_divisible_p((mpz_ptr) a, (mpz_ptr)
b) != 0;
218 static int nrzDivComp(number a, number
b,
const coeffs r)
220 if (nrzDivBy(a,
b, r))
222 if (nrzDivBy(
b, a, r))
return 2;
225 if (nrzDivBy(
b, a, r))
return 1;
229 static number nrzDiv (number a,number
b,
const coeffs)
235 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr)
b);
246 static number nrzExactDiv (number a,number
b,
const coeffs)
250 mpz_tdiv_q(erg, (mpz_ptr) a, (mpz_ptr)
b);
254 static number nrzEucNorm (number a,
const coeffs )
258 mpz_abs(
abs, (mpz_ptr)a);
263 static number nrzSmallestQuotRem (number a, number
b, number * r,
const coeffs )
269 int gsign = mpz_sgn((mpz_ptr)
b);
273 mpz_abs(gg, (mpz_ptr)
b);
274 mpz_fdiv_qr(qq, rr, (mpz_ptr) a, gg);
275 mpz_tdiv_q_2exp(ghalf, gg, 1);
276 if (mpz_cmp(rr, ghalf) > 0)
279 mpz_add_ui(qq, qq, 1);
281 if (gsign < 0) mpz_neg(qq, qq);
297 static number nrzQuotRem (number a, number
b, number * r,
const coeffs )
303 mpz_tdiv_qr(qq, rr, (mpz_ptr) a, (mpz_ptr)
b);
316 static number nrzIntMod (number a,number
b,
const coeffs)
322 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr)
b);
328 static number nrzInvers (number c,
const coeffs r)
330 if (!nrzIsUnit((number) c, r))
332 WerrorS(
"Non invertible element.");
338 static number nrzNeg (number c,
const coeffs)
345 static number nrzMapMachineInt(number from,
const coeffs ,
const coeffs )
348 mpz_init_set_ui(erg, (
unsigned long) from);
352 static number nrzMapZp(number from,
const coeffs ,
const coeffs )
355 mpz_init_set_si(erg, (
long) from);
359 static number nrzMapQ(number from,
const coeffs src,
const coeffs )
363 nlGMP(from, erg, src);
382 return nrzMapMachineInt;
399 void nrzSetExp(
int,
coeffs)
403 void nrzInitExp(
int,
coeffs)
408 static BOOLEAN nrzDBTest (number,
const char *,
const int,
const coeffs)
423 int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
425 z=mpz_get_str(
s,10,(mpz_ptr) a);
434 static const char * nlEatLongC(
char *
s, mpz_ptr
i)
436 const char * start=
s;
438 if (*s<'0' || *s>
'9')
443 while (*
s >=
'0' && *
s <=
'9')
s++;
446 mpz_set_str(
i,start,10);
452 mpz_set_str(
i,start,10);
465 mpz_init_set(
num, *((mpz_t*)
n));
478 if (!
n.den().isOne())
480 WarnS(
"denominator is not 1 in factory");
486 static const char * nrzRead (
const char *
s, number *a,
const coeffs)
491 s = nlEatLongC((
char *)
s,
z);
499 long ch = r->cfInt(c, r);
501 mpz_init_set_ui(dummy, ch);
504 info.exp = (
unsigned long) 1;
510 static number nrzInitMPZ(mpz_t
m,
const coeffs)
517 static number nrzFarey(number r, number
N,
const coeffs R)
519 number a0 = nrzCopy(
N,
R);
521 number a1 = nrzCopy(r,
R);
525 PrintS(
"Farey start with ");
533 number as = nrzMult(a1, a1,
R);
535 if (nrzGreater(
N, as,
R))
541 number q = nrzDiv(a0, a1,
R);
542 number t = nrzMult(a1, q,
R),
543 s = nrzSub(a0, t,
R);
549 t = nrzMult(b1, q,
R);
550 s = nrzSub(b0, t,
R);
557 number as = nrzMult(b1, b1,
R);
560 if (nrzGreater(as,
N,
R))
619 r->cfIntMod= nrzIntMod;
620 r->cfExactDiv= nrzExactDiv;
622 r->cfInitMPZ = nrzInitMPZ;
625 r->cfDivComp = nrzDivComp;
626 r->cfIsUnit = nrzIsUnit;
627 r->cfGetUnit = nrzGetUnit;
628 r->cfExtGcd = nrzExtGcd;
629 r->cfXExtGcd = nrzXExtGcd;
630 r->cfDivBy = nrzDivBy;
631 r->cfEucNorm = nrzEucNorm;
632 r->cfQuotRem = nrzSmallestQuotRem;
633 r->cfInpNeg = nrzNeg;
634 r->cfInvers= nrzInvers;
638 r->cfGreater = nrzGreater;
639 r->cfEqual = nrzEqual;
640 r->cfIsZero = nrzIsZero;
641 r->cfIsOne = nrzIsOne;
642 r->cfIsMOne = nrzIsMOne;
643 r->cfGreaterZero = nrzGreaterZero;
644 r->cfPower = nrzPower;
648 r->cfSetMap = nrzSetMap;
649 r->cfQuot1 = nrzQuot1;
650 r->convSingNFactoryN=nrzConvSingNFactoryN;
651 r->convFactoryNSingN=nrzConvFactoryNSingN;
659 r->cfDBTest=nrzDBTest;
663 r->has_simple_Alloc=
FALSE;
664 r->has_simple_Inverse=
FALSE;