version 1.4, 2017/02/22 04:53:13 |
version 1.7, 2021/03/25 07:03:21 |
|
|
#include "ox_pari.h" |
#include "ox_pari.h" |
|
|
|
int with_gmp; |
|
|
|
int gmp_check() |
|
{ |
|
GEN z1,z2; |
|
|
|
// z1=[*,*,1,2], z2=[*,*,2,1] |
|
// if gmp style => z1>z2 else z1<z2 |
|
z1 = cgeti(2+2); setsigne(z1,1); setlgefint(z1,lg(z1)); |
|
z1[2] = 1; z1[3] = 2; |
|
z2 = cgeti(2+2); setsigne(z2,1); setlgefint(z2,lg(z2)); |
|
z2[2] = 2; z2[3] = 1; |
|
if ( cmpii(z1,z2) > 0 ) with_gmp = 1; |
|
else with_gmp = 0; |
|
} |
|
|
GEN cmo_int32_to_GEN(cmo_int32 *c) |
GEN cmo_int32_to_GEN(cmo_int32 *c) |
{ |
{ |
GEN z; |
GEN z; |
Line 19 GEN cmo_int32_to_GEN(cmo_int32 *c) |
|
Line 35 GEN cmo_int32_to_GEN(cmo_int32 *c) |
|
return z; |
return z; |
} |
} |
|
|
|
GEN cmo_string_to_GEN(cmo_string *c) |
|
{ |
|
GEN z; |
|
int l; |
|
|
|
l = strlen(c->s); |
|
z = cgetg(l+1,t_STR); |
|
strcpy(GSTR(z),c->s); |
|
return z; |
|
} |
|
|
GEN cmo_zz_to_GEN(cmo_zz *c) |
GEN cmo_zz_to_GEN(cmo_zz *c) |
{ |
{ |
mpz_ptr mpz; |
mpz_ptr mpz; |
Line 31 GEN cmo_zz_to_GEN(cmo_zz *c) |
|
Line 58 GEN cmo_zz_to_GEN(cmo_zz *c) |
|
len = ABSIZ(mpz); |
len = ABSIZ(mpz); |
ptr = (long *)PTR(mpz); |
ptr = (long *)PTR(mpz); |
z = cgeti(len+2); |
z = cgeti(len+2); |
for ( j = 0; j < len; j++ ) |
if ( with_gmp ) // least signifcant first |
z[len-j+1] = ptr[j]; |
for ( j = 0; j < len; j++ ) |
|
z[j+2] = ptr[j]; |
|
else // most signifcant first |
|
for ( j = 0; j < len; j++ ) |
|
z[len-j+1] = ptr[j]; |
setsigne(z,sgn); |
setsigne(z,sgn); |
setlgefint(z,lg(z)); |
setlgefint(z,lg(z)); |
return z; |
return z; |
Line 106 GEN cmo_up_to_GEN(cmo_polynomial_in_one_variable *c) |
|
Line 137 GEN cmo_up_to_GEN(cmo_polynomial_in_one_variable *c) |
|
z = cgetg(d+3,t_POL); |
z = cgetg(d+3,t_POL); |
setsigne(z,1); |
setsigne(z,1); |
setvarn(z,c->var); |
setvarn(z,c->var); |
setlgef(z,d+3); |
setlg(z,d+3); |
for ( i = 2; i <= d+2; i++ ) |
for ( i = 2; i <= d+2; i++ ) |
z[i] = (long)gen_0; |
z[i] = (long)gen_0; |
for ( cell = c->head->next; cell != c->head; cell = cell->next ) { |
for ( cell = c->head->next; cell != c->head; cell = cell->next ) { |
Line 142 GEN cmo_rp_to_GEN(cmo_recursive_polynomial *c) |
|
Line 173 GEN cmo_rp_to_GEN(cmo_recursive_polynomial *c) |
|
} |
} |
} |
} |
|
|
|
cmo_zz *GEN_to_cmo_string(GEN z) |
|
{ |
|
cmo_string *c; |
|
|
|
c = new_cmo_string(GSTR(z)); |
|
return (cmo_zz *)c; |
|
} |
|
|
cmo_zz *GEN_to_cmo_zz(GEN z) |
cmo_zz *GEN_to_cmo_zz(GEN z) |
{ |
{ |
cmo_zz *c; |
cmo_zz *c; |
|
|
c = new_cmo_zz(); |
c = new_cmo_zz(); |
mpz_import(c->mpz,lgef(z)-2,1,sizeof(long),0,0,&z[2]); |
// -1:least significant first, 1:most significant first |
|
mpz_import(c->mpz,lg(z)-2,with_gmp?-1:1,sizeof(long),0,0,&z[2]); |
if ( signe(z) < 0 ) |
if ( signe(z) < 0 ) |
mpz_neg(c->mpz,c->mpz); |
mpz_neg(c->mpz,c->mpz); |
return c; |
return c; |
Line 161 cmo_qq *GEN_to_cmo_qq(GEN z) |
|
Line 201 cmo_qq *GEN_to_cmo_qq(GEN z) |
|
num = (GEN)z[1]; |
num = (GEN)z[1]; |
den = (GEN)z[2]; |
den = (GEN)z[2]; |
c = new_cmo_qq(); |
c = new_cmo_qq(); |
mpz_import(mpq_numref(c->mpq),lgef(num)-2,1,sizeof(long),0,0,&num[2]); |
mpz_import(mpq_numref(c->mpq),lg(num)-2,1,sizeof(long),0,0,&num[2]); |
mpz_import(mpq_denref(c->mpq),lgef(den)-2,1,sizeof(long),0,0,&den[2]); |
mpz_import(mpq_denref(c->mpq),lg(den)-2,1,sizeof(long),0,0,&den[2]); |
if ( signe(num)*signe(den) < 0 ) |
if ( signe(num)*signe(den) < 0 ) |
mpz_neg(mpq_numref(c->mpq),mpq_numref(c->mpq)); |
mpz_neg(mpq_numref(c->mpq),mpq_numref(c->mpq)); |
return c; |
return c; |
Line 266 GEN cmo_to_GEN(cmo *c) |
|
Line 306 GEN cmo_to_GEN(cmo *c) |
|
return cmo_rp_to_GEN((cmo_recursive_polynomial *)c); |
return cmo_rp_to_GEN((cmo_recursive_polynomial *)c); |
case CMO_POLYNOMIAL_IN_ONE_VARIABLE: |
case CMO_POLYNOMIAL_IN_ONE_VARIABLE: |
return cmo_up_to_GEN((cmo_polynomial_in_one_variable *)c); |
return cmo_up_to_GEN((cmo_polynomial_in_one_variable *)c); |
|
case CMO_STRING: |
|
return cmo_string_to_GEN((cmo_string *)c); |
default: |
default: |
return 0; |
return 0; |
} |
} |
Line 292 cmo *GEN_to_cmo(GEN z) |
|
Line 334 cmo *GEN_to_cmo(GEN z) |
|
return (cmo *)GEN_to_cmo_list(z); |
return (cmo *)GEN_to_cmo_list(z); |
case t_MAT: /* matrix */ |
case t_MAT: /* matrix */ |
return (cmo *)GEN_to_cmo_list(shallowtrans(z)); |
return (cmo *)GEN_to_cmo_list(shallowtrans(z)); |
|
case t_STR: /* string */ |
|
return (cmo *)GEN_to_cmo_string(z); |
default: |
default: |
sprintf(buf,"GEN_to_cmo : unsupported type=%d",(int)typ(z)); |
sprintf(buf,"GEN_to_cmo : unsupported type=%d",(int)typ(z)); |
return (cmo *)make_error2(buf); |
return (cmo *)make_error2(buf); |