version 1.9, 2001/06/07 04:54:38 |
version 1.10, 2001/10/09 01:36:06 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* |
* |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/int.c,v 1.8 2000/12/21 02:45:16 murao Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/int.c,v 1.9 2001/06/07 04:54:38 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
Line 57 void Pup2_init_eg(), Pup2_show_eg(); |
|
Line 57 void Pup2_init_eg(), Pup2_show_eg(); |
|
void Piqr(), Pprime(), Plprime(), Pinttorat(); |
void Piqr(), Pprime(), Plprime(), Pinttorat(); |
void Piand(), Pior(), Pixor(), Pishift(); |
void Piand(), Pior(), Pixor(), Pishift(); |
void Pisqrt(); |
void Pisqrt(); |
void iand(), ior(), ixor(); |
|
void isqrt(); |
|
void Plrandom(); |
void Plrandom(); |
void Pset_upkara(), Pset_uptkara(), Pset_up2kara(), Pset_upfft(); |
void Pset_upkara(), Pset_uptkara(), Pset_up2kara(), Pset_upfft(); |
void Pmt_save(), Pmt_load(); |
void Pmt_save(), Pmt_load(); |
Line 121 static unsigned int gcd_small(unsigned int,unsigned in |
|
Line 119 static unsigned int gcd_small(unsigned int,unsigned in |
|
int TypeT_NB_check(unsigned int, unsigned int); |
int TypeT_NB_check(unsigned int, unsigned int); |
int mpi_mag; |
int mpi_mag; |
|
|
void Pntoint32(arg,rp) |
void Pntoint32(NODE arg,USINT *rp) |
NODE arg; |
|
USINT *rp; |
|
{ |
{ |
Q q; |
Q q; |
unsigned int t; |
unsigned int t; |
|
|
error("ntoint32 : invalid argument"); |
error("ntoint32 : invalid argument"); |
t = BD(NM(q))[0]; |
t = BD(NM(q))[0]; |
if ( SGN(q) < 0 ) |
if ( SGN(q) < 0 ) |
t = -t; |
t = -(int)t; |
MKUSINT(*rp,t); |
MKUSINT(*rp,t); |
} |
} |
|
|
void Pint32ton(arg,rp) |
void Pint32ton(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
int t; |
int t; |
|
|
|
|
STOQ(t,*rp); |
STOQ(t,*rp); |
} |
} |
|
|
void Pdp_set_mpi(arg,rp) |
void Pdp_set_mpi(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
if ( arg ) { |
if ( arg ) { |
asir_assert(ARG0(arg),O_N,"dp_set_mpi"); |
asir_assert(ARG0(arg),O_N,"dp_set_mpi"); |
|
|
STOQ(mpi_mag,*rp); |
STOQ(mpi_mag,*rp); |
} |
} |
|
|
void Psmall_jacobi(arg,rp) |
void Psmall_jacobi(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
Q a,m; |
Q a,m; |
int a0,m0,s; |
int a0,m0,s; |
|
|
} |
} |
} |
} |
|
|
int small_jacobi(a,m) |
int small_jacobi(int a,int m) |
int a,m; |
|
{ |
{ |
int m4,m8,a4,j1,i,s; |
int m4,m8,a4,j1,i,s; |
|
|
|
|
} |
} |
} |
} |
|
|
void Ptype_t_NB(arg,rp) |
void Ptype_t_NB(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
if ( TypeT_NB_check(QTOS((Q)ARG0(arg)),QTOS((Q)ARG1(arg)))) |
if ( TypeT_NB_check(QTOS((Q)ARG0(arg)),QTOS((Q)ARG1(arg)))) |
*rp = ONE; |
*rp = ONE; |
Line 287 static unsigned int gcd_small(unsigned int a,unsigned |
|
Line 274 static unsigned int gcd_small(unsigned int a,unsigned |
|
} |
} |
} |
} |
|
|
void Pmt_save(arg,rp) |
void Pmt_save(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
int ret; |
int ret; |
|
|
|
|
STOQ(ret,*rp); |
STOQ(ret,*rp); |
} |
} |
|
|
void Pmt_load(arg,rp) |
void Pmt_load(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
int ret; |
int ret; |
|
|
|
|
STOQ(ret,*rp); |
STOQ(ret,*rp); |
} |
} |
|
|
void Pisqrt(arg,rp) |
void Pisqrt(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
Q a; |
Q a; |
N r; |
N r; |
|
|
} |
} |
} |
} |
|
|
void Pidiv(arg,rp) |
void Pidiv(NODE arg,Obj *rp) |
NODE arg; |
|
Obj *rp; |
|
{ |
{ |
N q,r; |
N q,r; |
Q a; |
Q a; |
|
|
} |
} |
} |
} |
|
|
void Pirem(arg,rp) |
void Pirem(NODE arg,Obj *rp) |
NODE arg; |
|
Obj *rp; |
|
{ |
{ |
N q,r; |
N q,r; |
Q a; |
Q a; |
|
|
} |
} |
} |
} |
|
|
void Piqr(arg,rp) |
void Piqr(NODE arg,LIST *rp) |
NODE arg; |
|
LIST *rp; |
|
{ |
{ |
N q,r; |
N q,r; |
Q a,b; |
Q a,b; |
|
|
MKNODE(node2,b,0); MKNODE(node1,a,node2); MKLIST(*rp,node1); |
MKNODE(node2,b,0); MKNODE(node1,a,node2); MKLIST(*rp,node1); |
} |
} |
|
|
void Pinttorat(arg,rp) |
void Pinttorat(NODE arg,LIST *rp) |
NODE arg; |
|
LIST *rp; |
|
{ |
{ |
Q cq,qq,t,u1,v1,r1,nm; |
Q cq,qq,t,u1,v1,r1,nm; |
N m,b,q,r,c,u2,v2,r2; |
N m,b,q,r,c,u2,v2,r2; |
|
|
} |
} |
} |
} |
|
|
void Pigcd(arg,rp) |
void Pigcd(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
N g; |
N g; |
Q n1,n2,a; |
Q n1,n2,a; |
|
|
} |
} |
} |
} |
|
|
int comp_n(a,b) |
int comp_n(N *a,N *b) |
N *a,*b; |
|
{ |
{ |
return cmpn(*a,*b); |
return cmpn(*a,*b); |
} |
} |
|
|
void iqrv(a,dvr,rp) |
void iqrv(VECT a,Q dvr,LIST *rp) |
VECT a; |
|
Q dvr; |
|
LIST *rp; |
|
{ |
{ |
int i,n; |
int i,n; |
VECT q,r; |
VECT q,r; |
|
|
* gcd = GCD(a,b), ca = a/g, cb = b/g |
* gcd = GCD(a,b), ca = a/g, cb = b/g |
*/ |
*/ |
|
|
void igcd_cofactor(a,b,gcd,ca,cb) |
void igcd_cofactor(Q a,Q b,Q *gcd,Q *ca,Q *cb) |
Q a,b; |
|
Q *gcd,*ca,*cb; |
|
{ |
{ |
N gn,tn; |
N gn,tn; |
|
|
|
|
} |
} |
} |
} |
|
|
void igcdv(a,rp) |
void igcdv(VECT a,Q *rp) |
VECT a; |
|
Q *rp; |
|
{ |
{ |
int i,j,n,nz; |
int i,j,n,nz; |
N g,gt,q,r; |
N g,gt,q,r; |
|
|
NTOQ(g,1,*rp); |
NTOQ(g,1,*rp); |
} |
} |
|
|
void igcdv_estimate(a,rp) |
void igcdv_estimate(VECT a,Q *rp) |
VECT a; |
|
Q *rp; |
|
{ |
{ |
int n,i,m; |
int n,i,m; |
N s,t,u,g; |
N s,t,u,g; |
|
|
gcdn(s,t,&g); NTOQ(g,1,*rp); |
gcdn(s,t,&g); NTOQ(g,1,*rp); |
} |
} |
|
|
void Pilcm(arg,rp) |
void Pilcm(NODE arg,Obj *rp) |
NODE arg; |
|
Obj *rp; |
|
{ |
{ |
N g,q,r,l; |
N g,q,r,l; |
Q n1,n2,a; |
Q n1,n2,a; |
|
|
} |
} |
} |
} |
|
|
void Piand(arg,rp) |
void Piand(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
N g; |
N g; |
Q n1,n2,a; |
Q n1,n2,a; |
|
|
} |
} |
} |
} |
|
|
void Pior(arg,rp) |
void Pior(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
N g; |
N g; |
Q n1,n2,a; |
Q n1,n2,a; |
|
|
} |
} |
} |
} |
|
|
void Pixor(arg,rp) |
void Pixor(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
N g; |
N g; |
Q n1,n2,a; |
Q n1,n2,a; |
|
|
} |
} |
} |
} |
|
|
void Pishift(arg,rp) |
void Pishift(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
N g; |
N g; |
Q n1,s,a; |
Q n1,s,a; |
|
|
} |
} |
} |
} |
|
|
void isqrt(a,r) |
void isqrt(N a,N *r) |
N a,*r; |
|
{ |
{ |
int k; |
int k; |
N x,t,x2,xh,quo,rem; |
N x,t,x2,xh,quo,rem; |
|
|
} |
} |
} |
} |
|
|
void iand(n1,n2,r) |
void iand(N n1,N n2,N *r) |
N n1,n2,*r; |
|
{ |
{ |
int d1,d2,d,i; |
int d1,d2,d,i; |
N nr; |
N nr; |
|
|
} |
} |
} |
} |
|
|
void ior(n1,n2,r) |
void ior(N n1,N n2,N *r) |
N n1,n2,*r; |
|
{ |
{ |
int d1,d2,i; |
int d1,d2,i; |
N nr; |
N nr; |
|
|
} |
} |
} |
} |
|
|
void ixor(n1,n2,r) |
void ixor(N n1,N n2,N *r) |
N n1,n2,*r; |
|
{ |
{ |
int d1,d2,i; |
int d1,d2,i; |
N nr; |
N nr; |
|
|
} |
} |
} |
} |
|
|
void Pup2_init_eg(rp) |
void Pup2_init_eg(Obj *rp) |
Obj *rp; |
|
{ |
{ |
up2_init_eg(); |
up2_init_eg(); |
*rp = 0; |
*rp = 0; |
} |
} |
|
|
void Pup2_show_eg(rp) |
void Pup2_show_eg(Obj *rp) |
Obj *rp; |
|
{ |
{ |
up2_show_eg(); |
up2_show_eg(); |
*rp = 0; |
*rp = 0; |
} |
} |
|
|
void Pgf2nton(arg,rp) |
void Pgf2nton(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
if ( !ARG0(arg) ) |
if ( !ARG0(arg) ) |
*rp = 0; |
*rp = 0; |
|
|
up2ton(((GF2N)ARG0(arg))->body,rp); |
up2ton(((GF2N)ARG0(arg))->body,rp); |
} |
} |
|
|
void Pntogf2n(arg,rp) |
void Pntogf2n(NODE arg,GF2N *rp) |
NODE arg; |
|
GF2N *rp; |
|
{ |
{ |
UP2 t; |
UP2 t; |
|
|
|
|
MKGF2N(t,*rp); |
MKGF2N(t,*rp); |
} |
} |
|
|
void Pup2_inv(arg,rp) |
void Pup2_inv(NODE arg,P *rp) |
NODE arg; |
|
P *rp; |
|
{ |
{ |
UP2 a,b,t; |
UP2 a,b,t; |
|
|
|
|
up2top(t,rp); |
up2top(t,rp); |
} |
} |
|
|
void Pinv(arg,rp) |
void Pinv(NODE arg,Num *rp) |
NODE arg; |
|
Num *rp; |
|
{ |
{ |
Num n; |
Num n; |
Q mod; |
Q mod; |
|
|
} |
} |
} |
} |
|
|
void Pfac(arg,rp) |
void Pfac(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
asir_assert(ARG0(arg),O_N,"fac"); |
asir_assert(ARG0(arg),O_N,"fac"); |
factorial(QTOS((Q)ARG0(arg)),rp); |
factorial(QTOS((Q)ARG0(arg)),rp); |
} |
} |
|
|
void Plrandom(arg,rp) |
void Plrandom(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
N r; |
N r; |
|
|
|
|
NTOQ(r,1,*rp); |
NTOQ(r,1,*rp); |
} |
} |
|
|
void Prandom(arg,rp) |
void Prandom(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
unsigned int r; |
unsigned int r; |
|
|
Line 902 unsigned int random() { |
|
Line 833 unsigned int random() { |
|
return R_Next = (R_Next * 1103515245 + 12345); |
return R_Next = (R_Next * 1103515245 + 12345); |
} |
} |
|
|
void srandom(s) |
void srandom(unsigned int s) |
unsigned int s; |
|
{ |
{ |
if ( s ) |
if ( s ) |
R_Next = s; |
R_Next = s; |
|
|
} |
} |
#endif |
#endif |
|
|
void Pprime(arg,rp) |
void Pprime(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
int i; |
int i; |
|
|
|
|
STOQ(sprime[i],*rp); |
STOQ(sprime[i],*rp); |
} |
} |
|
|
void Plprime(arg,rp) |
void Plprime(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
int i,p; |
int i,p; |
|
|
|
|
|
|
extern int up_kara_mag, up_tkara_mag, up_fft_mag; |
extern int up_kara_mag, up_tkara_mag, up_fft_mag; |
|
|
void Pset_upfft(arg,rp) |
void Pset_upfft(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
if ( arg ) { |
if ( arg ) { |
asir_assert(ARG0(arg),O_N,"set_upfft"); |
asir_assert(ARG0(arg),O_N,"set_upfft"); |
|
|
STOQ(up_fft_mag,*rp); |
STOQ(up_fft_mag,*rp); |
} |
} |
|
|
void Pset_upkara(arg,rp) |
void Pset_upkara(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
if ( arg ) { |
if ( arg ) { |
asir_assert(ARG0(arg),O_N,"set_upkara"); |
asir_assert(ARG0(arg),O_N,"set_upkara"); |
|
|
STOQ(up_kara_mag,*rp); |
STOQ(up_kara_mag,*rp); |
} |
} |
|
|
void Pset_uptkara(arg,rp) |
void Pset_uptkara(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
if ( arg ) { |
if ( arg ) { |
asir_assert(ARG0(arg),O_N,"set_uptkara"); |
asir_assert(ARG0(arg),O_N,"set_uptkara"); |
|
|
|
|
extern int up2_kara_mag; |
extern int up2_kara_mag; |
|
|
void Pset_up2kara(arg,rp) |
void Pset_up2kara(NODE arg,Q *rp) |
NODE arg; |
|
Q *rp; |
|
{ |
{ |
if ( arg ) { |
if ( arg ) { |
asir_assert(ARG0(arg),O_N,"set_up2kara"); |
asir_assert(ARG0(arg),O_N,"set_up2kara"); |
|
|
STOQ(up2_kara_mag,*rp); |
STOQ(up2_kara_mag,*rp); |
} |
} |
|
|
void Pigcdbin(arg,rp) |
void Pigcdbin(NODE arg,Obj *rp) |
NODE arg; |
|
Obj *rp; |
|
{ |
{ |
N g; |
N g; |
Q n1,n2,a; |
Q n1,n2,a; |
|
|
} |
} |
} |
} |
|
|
void Pigcdbmod(arg,rp) |
void Pigcdbmod(NODE arg,Obj *rp) |
NODE arg; |
|
Obj *rp; |
|
{ |
{ |
N g; |
N g; |
Q n1,n2,a; |
Q n1,n2,a; |
|
|
} |
} |
} |
} |
|
|
void Pigcdacc(arg,rp) |
void Pigcdacc(NODE arg,Obj *rp) |
NODE arg; |
|
Obj *rp; |
|
{ |
{ |
N g; |
N g; |
Q n1,n2,a; |
Q n1,n2,a; |
|
|
} |
} |
} |
} |
|
|
void PigcdEuc(arg,rp) |
void PigcdEuc(NODE arg,Obj *rp) |
NODE arg; |
|
Obj *rp; |
|
{ |
{ |
N g; |
N g; |
Q n1,n2,a; |
Q n1,n2,a; |
Line 1088 extern int igcdacc_thre; |
|
Line 998 extern int igcdacc_thre; |
|
* > igcdacc_thre, "bmod" reduction is done. |
* > igcdacc_thre, "bmod" reduction is done. |
*/ |
*/ |
|
|
void Pigcdcntl(arg,rp) |
void Pigcdcntl(NODE arg,Obj *rp) |
NODE arg; |
|
Obj *rp; |
|
{ |
{ |
Obj p; |
Obj p; |
Q a; |
Q a; |