version 1.13, 2019/03/18 07:00:33 |
version 1.14, 2019/03/27 07:45:53 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2018/engine/Q.c,v 1.12 2019/03/17 02:48:13 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2018/engine/Q.c,v 1.13 2019/03/18 07:00:33 noro Exp $ */ |
#include "ca.h" |
#include "ca.h" |
#include "gmp.h" |
#include "gmp.h" |
#include "base.h" |
#include "base.h" |
Line 1337 int mpz_inttorat(mpz_t c,mpz_t m,mpz_t b,mpz_t nm,mpz_ |
|
Line 1337 int mpz_inttorat(mpz_t c,mpz_t m,mpz_t b,mpz_t nm,mpz_ |
|
} |
} |
if ( mpz_cmp(v1,b) >= 0 ) return 0; |
if ( mpz_cmp(v1,b) >= 0 ) return 0; |
else { |
else { |
|
mpz_gcd(t,v1,v2); |
|
if ( UNIMPZ(t) ) |
|
mpz_set_ui(r1,0); |
|
else { |
|
/* v1 /= t, v2 /= t, t=c*v1-v2, r1=t%m */ |
|
mpz_divexact(v1,v1,t); mpz_divexact(v2,v2,t); |
|
mpz_mul(t,c,v1); mpz_sub(t,t,v2); mpz_mod(r1,t,m); |
|
} |
|
if ( mpz_sgn(r1) ) return 0; |
if ( mpz_sgn(v1)<0 ) { |
if ( mpz_sgn(v1)<0 ) { |
mpz_neg(dn,v1); mpz_neg(nm,v2); |
mpz_neg(dn,v1); mpz_neg(nm,v2); |
} else { |
} else { |
Line 1348 int mpz_inttorat(mpz_t c,mpz_t m,mpz_t b,mpz_t nm,mpz_ |
|
Line 1357 int mpz_inttorat(mpz_t c,mpz_t m,mpz_t b,mpz_t nm,mpz_ |
|
|
|
int inttorat(Z c,Z m,Z b,Z *nmp,Z *dnp) |
int inttorat(Z c,Z m,Z b,Z *nmp,Z *dnp) |
{ |
{ |
Z qq,t,u1,v1,r1; |
Z qq,t,s,r,u1,v1,r1; |
Z q,u2,v2,r2; |
Z q,u2,v2,r2; |
|
|
u1 = 0; v1 = ONE; u2 = m; v2 = c; |
u1 = 0; v1 = ONE; u2 = m; v2 = c; |
Line 1358 int inttorat(Z c,Z m,Z b,Z *nmp,Z *dnp) |
|
Line 1367 int inttorat(Z c,Z m,Z b,Z *nmp,Z *dnp) |
|
} |
} |
if ( cmpz(v1,b) >= 0 ) return 0; |
if ( cmpz(v1,b) >= 0 ) return 0; |
else { |
else { |
if ( mpz_sgn(BDY(v1))<0 ) { |
/* reduction and check */ |
chsgnz(v1,dnp); chsgnz(v2,nmp); |
/* v2/v1 = u2/u1, c*u1-u2 = 0 mod m? */ |
|
gcdz(v1,v2,&t); |
|
if ( UNIZ(t) ) { |
|
u1 = v1; u2 = v2; r = 0; |
} else { |
} else { |
*dnp = v1; *nmp = v2; |
divsz(v1,t,&u1); divsz(v2,t,&u2); |
|
mulz(c,u1,&t); subz(t,u2,&s); remz(s,m,&r); |
|
} |
|
if ( r ) return 0; |
|
if ( mpz_sgn(BDY(u1))<0 ) { |
|
chsgnz(u1,dnp); chsgnz(u2,nmp); |
|
} else { |
|
*dnp = u1; *nmp = u2; |
} |
} |
return 1; |
return 1; |
} |
} |