Ilya Zakharevich on Mon, 9 Nov 1998 01:18:23 -0500 (EST) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
PARI translated to C |
Currently PARI uses assembler-like handling of GENs. This patch provides new C-style definition for GEN and the subtypes for GEN. Minor changes to .h files are done to fix signatures of functions if appropriate. Backward compatibility is preserved when PARI_OLD_GEN is defined before inclusion of pari.h. No *.c files of PARI library has been changed to follow new conventions, but ./example/matexp.c is. Note that for the style matexp.c is written in the advantages of the new style are minuscule (you need no less type conversions from/to generic type), but for functions which need to access components of GENs the advantage should be obvious. Moreover, a transition to C++ may make most of the casts go away. Note that the names of new types (valFRAC etc.) need improvement, but I cannot introduce anything better right now. Enjoy, Ilya diff -pru ./src.ini/headers/parigen.h ./src/headers/parigen.h --- ./src.ini/headers/parigen.h Fri Nov 6 10:08:48 1998 +++ ./src/headers/parigen.h Sun Nov 8 23:25:54 1998 @@ -2,12 +2,200 @@ /* This file defines the parameters of the GEN type */ /* $Id: parigen.h,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ -typedef long *GEN; -typedef int (*QSCOMP)(const void *, const void *); #ifdef ULONG_NOT_DEFINED typedef unsigned long ulong; #endif +#ifdef PARI_OLD_GEN + +typedef long valGEN; +typedef long valINT; +typedef long valREAL; +typedef long valINTMOD; +typedef long valFRAC; +typedef long valFRACN; +typedef long valCOMPLEX; +typedef long valPADIC; +typedef long valQUAD; +typedef long valPOLMOD; +typedef long valPOL; +typedef long valSER; +typedef long valRFRAC; +typedef long valRFRACN; +typedef long valQFR; +typedef long valQFI; +typedef long valVEC; +typedef long valCOL; +typedef long valMAT; +typedef long valLIST; +typedef long valSTR; + +/* These macros are temporary for the transition period. */ +# define GENheader(z) (((GEN)(z))[0]) +# define GENdescr(z) (((GEN)(z))[1]) +# define valINTbuffer(z,i) (((GEN)(z))[2+(i)]) + +#else /* !( defined PARI_OLD_GEN ) */ + +/* Should be bitfields! */ +# define GEN_LEADER ulong header +# define GEN_DESCR ulong descr + +/* These macros are temporary for the transition period. */ +# define GENheader(z) (((GEN)(z))->int_val.header) +# define GENdescr(z) (((GEN)(z))->int_val.descr) +# define valINTbuffer(z,i) (((valINT*)(z))->data[(i)]) + +union valGEN; +struct valPOL; + +typedef struct valINT { + GEN_LEADER; + GEN_DESCR; + ulong data[1]; +} valINT; + +typedef struct valREAL { + GEN_LEADER; + GEN_DESCR; + ulong mantissa[1]; +} valREAL; + +typedef struct valINTMOD { + GEN_LEADER; + valINT *modulus; + valINT *repres; +} valINTMOD; + +typedef struct valFRAC { + GEN_LEADER; + valINT *numer; + valINT *denom; +} valFRAC; + +typedef struct valFRACN { + GEN_LEADER; + valINT *numer; + valINT *denom; +} valFRACN; + +typedef struct valCOMPLEX { + GEN_LEADER; + union valGEN *real; + union valGEN *imag; +} valCOMPLEX; + +typedef struct valPADIC { + GEN_LEADER; + GEN_DESCR; + valINT *prime; + valINT *error; + valINT *normalized; +} valPADIC; + +typedef struct valQUAD { + GEN_LEADER; + struct valPOL *poly; + union valGEN *real; + union valGEN *imag; +} valQUAD; + +typedef struct valPOLMOD { + GEN_LEADER; + struct valPOL *modulus; + struct valPOL *repres; +} valPOLMOD; + +typedef struct valPOL { + GEN_LEADER; + GEN_DESCR; + union valGEN *coeff[1]; +} valPOL; + +typedef struct valSER { + GEN_LEADER; + GEN_DESCR; + union valGEN *coeff[1]; +} valSER; + +typedef struct valRFRAC { + GEN_LEADER; + valPOL *numer; + valPOL *denom; +} valRFRAC; + +typedef struct valRFRACN { + GEN_LEADER; + valPOL *numer; + valPOL *denom; +} valRFRACN; + +typedef struct valQFR { + GEN_LEADER; + valINT *coef[3]; + valREAL *dist; +} valQFR; + +typedef struct valQFI { + GEN_LEADER; + valINT *coef[3]; +} valQFI; + +typedef struct valVEC { + GEN_LEADER; + union valGEN *elt[1]; +} valVEC; + +typedef struct valCOL { + GEN_LEADER; + union valGEN *elt[1]; +} valCOL; + +typedef struct valMAT { + GEN_LEADER; + valCOL *elt[1]; +} valMAT; + +typedef struct valLIST { + GEN_LEADER; + GEN_DESCR; + union valGEN *elt[1]; +} valLIST; + +typedef struct valSTR { + GEN_LEADER; + char *s; +} valSTR; + +typedef union valGEN { + long old; + valINT int_val; + valREAL real; + valINTMOD intmod; + valFRAC frac; + valFRACN fracn; + valCOMPLEX complex_val; + valPADIC padic; + valQUAD quad; + valPOLMOD polmod; + valPOL pol; + valSER ser; + valRFRAC rfrac; + valRFRACN rfracn; + valQFR qfr; + valQFI qfi; + valVEC vec; + valCOL col; + valMAT mat; + valLIST list; + valSTR str; +} valGEN; +#endif /* !( defined PARI_OLD_GEN ) */ + +typedef valGEN *GEN; + +typedef int (*QSCOMP)(const void *, const void *); + #ifdef __M68K__ # define OLD_CODES #endif @@ -124,42 +312,45 @@ typedef int (*QSCOMP)(const void *, cons #define m_evallg(x) (x) #define m_evallgef(x) (x) -#define typ(x) (((ulong) ((GEN) (x))[0]) >> TYPSHIFT) -#define settyp(x,s) (((GEN)(x))[0]=\ - (((GEN)(x))[0]&(~TYPBITS)) | evaltyp(s)) - -#define isclone(x) (((GEN) (x))[0] & CLONEBIT) -#define setisclone(x) (((GEN) (x))[0] |= CLONEBIT) -#define unsetisclone(x) (((GEN) (x))[0] &= (~CLONEBIT)) - -#define lg(x) ((long) (((GEN) (x))[0] & LGBITS)) -#define setlg(x,s) (((GEN)(x))[0]=\ - (((GEN)(x))[0]&(~LGBITS)) | evallg(s)) - -#define signe(x) (((long) ((GEN) (x))[1]) >> SIGNSHIFT) -#define setsigne(x,s) (((GEN)(x))[1]=\ - (((GEN)(x))[1]&(~SIGNBITS)) | evalsigne(s)) - -#define lgef(x) ((long) (((GEN) (x))[1] & LGEFBITS)) -#define setlgef(x,s) (((GEN)(x))[1]=\ - (((GEN)(x))[1]&(~LGEFBITS)) | evallgef(s)) - -#define lgefint(x) ((long) (((GEN) (x))[1] & LGEFINTBITS)) -#define setlgefint(x,s) (((GEN)(x))[1]=\ - (((GEN)(x))[1]&(~LGEFINTBITS)) | evallgefint(s)) - -#define expo(x) ((long) ((((GEN) (x))[1] & EXPOBITS) - HIGHEXPOBIT)) -#define setexpo(x,s) (((GEN)(x))[1]=\ - (((GEN)(x))[1]&(~EXPOBITS)) | evalexpo(s)) - -#define valp(x) ((long) ((((GEN)(x))[1] & VALPBITS) - HIGHVALPBIT)) -#define setvalp(x,s) (((GEN)(x))[1]=\ - (((GEN)(x))[1]&(~VALPBITS)) | evalvalp(s)) - -#define precp(x) ((long) (((ulong) ((GEN) (x))[1]) >> PRECPSHIFT)) -#define setprecp(x,s) (((GEN)(x))[1]=\ - (((GEN)(x))[1]&(~PRECPBITS)) | evalprecp(s)) - -#define varn(x) ((long) ((((GEN) (x))[1]&VARNBITS) >> VARNSHIFT)) -#define setvarn(x,s) (((GEN)(x))[1]=\ - (((GEN)(x))[1]&(~VARNBITS)) | evalvarn(s)) +#define typ(x) (((ulong) GENheader(x)) >> TYPSHIFT) +#define settyp(x,s) (GENheader(x)=\ + (GENheader(x)&(~TYPBITS)) | evaltyp(s)) + +#define isclone(x) (GENheader(x) & CLONEBIT) +#define setisclone(x) (GENheader(x) |= CLONEBIT) +#define unsetisclone(x) (GENheader(x) &= (~CLONEBIT)) + +#define lg(x) ((long) (GENheader(x) & LGBITS)) +#define setlg(x,s) (GENheader(x)=\ + (GENheader(x)&(~LGBITS)) | evallg(s)) + +#define signe(x) (((long) GENdescr(x)) >> SIGNSHIFT) +#define setsigne(x,s) (GENdescr(x)=\ + (GENdescr(x)&(~SIGNBITS)) | evalsigne(s)) + +#define lgef(x) ((long) (GENdescr(x) & LGEFBITS)) +#define setlgef(x,s) (GENdescr(x)=\ + (GENdescr(x)&(~LGEFBITS)) | evallgef(s)) + +#define lgefint(x) ((long) (GENdescr(x) & LGEFINTBITS)) +#define setlgefint(x,s) (GENdescr(x)=\ + (GENdescr(x)&(~LGEFINTBITS)) | evallgefint(s)) + +#define expo(x) ((long) ((GENdescr(x) & EXPOBITS) - HIGHEXPOBIT)) +#define setexpo(x,s) (GENdescr(x)=\ + (GENdescr(x)&(~EXPOBITS)) | evalexpo(s)) + +#define valp(x) ((long) ((GENdescr(x) & VALPBITS) - HIGHVALPBIT)) +#define setvalp(x,s) (GENdescr(x)=\ + (GENdescr(x)&(~VALPBITS)) | evalvalp(s)) + +#define precp(x) ((long) (((ulong) GENdescr(x)) >> PRECPSHIFT)) +#define setprecp(x,s) (GENdescr(x)=\ + (GENdescr(x)&(~PRECPBITS)) | evalprecp(s)) + +#define varn(x) ((long) ((GENdescr(x)&VARNBITS) >> VARNSHIFT)) +#define setvarn(x,s) (GENdescr(x)=\ + (GENdescr(x)&(~VARNBITS)) | evalvarn(s)) + +#define NEWvalINT(l) ((valINT*)cgeti(l+2)) +#define NEWvalREAL(l) ((valREAL*)cgetr(l+2)) diff -pru ./src.ini/basemath/alglin1.c ./src/basemath/alglin1.c --- ./src.ini/basemath/alglin1.c Fri Nov 6 10:08:28 1998 +++ ./src/basemath/alglin1.c Sun Nov 8 21:26:04 1998 @@ -7,6 +7,8 @@ /********************************************************************/ /********************************************************************/ /* $Id: alglin1.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" /*******************************************************************/ diff -pru ./src.ini/basemath/alglin2.c ./src/basemath/alglin2.c --- ./src.ini/basemath/alglin2.c Fri Nov 6 10:07:58 1998 +++ ./src/basemath/alglin2.c Sun Nov 8 21:26:04 1998 @@ -7,6 +7,8 @@ /********************************************************************/ /********************************************************************/ /* $Id: alglin2.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" /*******************************************************************/ diff -pru ./src.ini/basemath/arith1.c ./src/basemath/arith1.c --- ./src.ini/basemath/arith1.c Fri Nov 6 10:07:58 1998 +++ ./src/basemath/arith1.c Sun Nov 8 21:26:04 1998 @@ -7,6 +7,8 @@ /*********************************************************************/ /*********************************************************************/ /* $Id: arith1.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" /*********************************************************************/ diff -pru ./src.ini/basemath/arith2.c ./src/basemath/arith2.c --- ./src.ini/basemath/arith2.c Fri Nov 6 10:08:00 1998 +++ ./src/basemath/arith2.c Sun Nov 8 21:26:04 1998 @@ -7,6 +7,8 @@ /*********************************************************************/ /*********************************************************************/ /* $Id: arith2.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" GEN arith_proto(long f(GEN), GEN x, int do_error); diff -pru ./src.ini/basemath/base1.c ./src/basemath/base1.c --- ./src.ini/basemath/base1.c Fri Nov 6 10:08:00 1998 +++ ./src/basemath/base1.c Sun Nov 8 21:26:04 1998 @@ -6,6 +6,8 @@ /**************************************************************/ /**************************************************************/ /* $Id: base1.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "parinf.h" diff -pru ./src.ini/basemath/base2.c ./src/basemath/base2.c --- ./src.ini/basemath/base2.c Fri Nov 6 10:08:02 1998 +++ ./src/basemath/base2.c Sun Nov 8 21:26:04 1998 @@ -6,6 +6,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: base2.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" GEN element_muli(GEN nf, GEN x, GEN y); diff -pru ./src.ini/basemath/base3.c ./src/basemath/base3.c --- ./src.ini/basemath/base3.c Fri Nov 6 10:08:04 1998 +++ ./src/basemath/base3.c Sun Nov 8 21:26:04 1998 @@ -6,6 +6,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: base3.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" /*******************************************************************/ diff -pru ./src.ini/basemath/base4.c ./src/basemath/base4.c --- ./src.ini/basemath/base4.c Fri Nov 6 10:08:04 1998 +++ ./src/basemath/base4.c Sun Nov 8 21:26:04 1998 @@ -7,6 +7,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: base4.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "parinf.h" diff -pru ./src.ini/basemath/base5.c ./src/basemath/base5.c --- ./src.ini/basemath/base5.c Fri Nov 6 10:08:06 1998 +++ ./src/basemath/base5.c Sun Nov 8 21:26:04 1998 @@ -7,6 +7,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: base5.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" GEN diff -pru ./src.ini/basemath/bibli1.c ./src/basemath/bibli1.c --- ./src.ini/basemath/bibli1.c Fri Nov 6 10:08:06 1998 +++ ./src/basemath/bibli1.c Sun Nov 8 21:26:04 1998 @@ -6,6 +6,8 @@ /********************************************************************/ /********************************************************************/ /* $Id: bibli1.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "parinf.h" /* scalar product of x with himself */ diff -pru ./src.ini/basemath/bibli2.c ./src/basemath/bibli2.c --- ./src.ini/basemath/bibli2.c Fri Nov 6 10:08:08 1998 +++ ./src/basemath/bibli2.c Sun Nov 8 21:26:04 1998 @@ -7,6 +7,8 @@ /********************************************************************/ /********************************************************************/ /* $Id: bibli2.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" /********************************************************************/ diff -pru ./src.ini/basemath/buch1.c ./src/basemath/buch1.c --- ./src.ini/basemath/buch1.c Fri Nov 6 10:08:08 1998 +++ ./src/basemath/buch1.c Sun Nov 8 21:26:04 1998 @@ -7,6 +7,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: buch1.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" /* See buch2.c: diff -pru ./src.ini/basemath/buch2.c ./src/basemath/buch2.c --- ./src.ini/basemath/buch2.c Fri Nov 6 10:08:10 1998 +++ ./src/basemath/buch2.c Sun Nov 8 21:26:04 1998 @@ -7,6 +7,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: buch2.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "parinf.h" diff -pru ./src.ini/basemath/buch3.c ./src/basemath/buch3.c --- ./src.ini/basemath/buch3.c Fri Nov 6 10:08:12 1998 +++ ./src/basemath/buch3.c Sun Nov 8 21:26:06 1998 @@ -6,6 +6,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: buch3.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "parinf.h" diff -pru ./src.ini/basemath/buch4.c ./src/basemath/buch4.c --- ./src.ini/basemath/buch4.c Fri Nov 6 10:08:12 1998 +++ ./src/basemath/buch4.c Sun Nov 8 21:26:06 1998 @@ -7,6 +7,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: buch4.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" static long diff -pru ./src.ini/basemath/gen1.c ./src/basemath/gen1.c --- ./src.ini/basemath/gen1.c Fri Nov 6 10:08:14 1998 +++ ./src/basemath/gen1.c Sun Nov 8 21:26:06 1998 @@ -7,6 +7,8 @@ /********************************************************************/ /********************************************************************/ /* $Id: gen1.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #define swapspec(x,y, nx,ny) {long _a=nx;GEN _z=x; nx=ny; ny=_a; x=y; y=_z;} diff -pru ./src.ini/basemath/gen2.c ./src/basemath/gen2.c --- ./src.ini/basemath/gen2.c Sun Nov 8 16:47:22 1998 +++ ./src/basemath/gen2.c Sun Nov 8 21:26:06 1998 @@ -7,6 +7,8 @@ /********************************************************************/ /********************************************************************/ /* $Id: gen2.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" /*******************************************************************/ diff -pru ./src.ini/basemath/gen3.c ./src/basemath/gen3.c --- ./src.ini/basemath/gen3.c Fri Nov 6 10:08:16 1998 +++ ./src/basemath/gen3.c Sun Nov 8 21:26:06 1998 @@ -7,6 +7,8 @@ /********************************************************************/ /********************************************************************/ /* $Id: gen3.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" /********************************************************************/ diff -pru ./src.ini/basemath/ifactor1.c ./src/basemath/ifactor1.c --- ./src.ini/basemath/ifactor1.c Fri Nov 6 10:08:18 1998 +++ ./src/basemath/ifactor1.c Sun Nov 8 21:26:06 1998 @@ -1,4 +1,6 @@ /* $Id: ifactor1.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" /*********************************************************************/ diff -pru ./src.ini/basemath/polarit1.c ./src/basemath/polarit1.c --- ./src.ini/basemath/polarit1.c Fri Nov 6 10:08:20 1998 +++ ./src/basemath/polarit1.c Sun Nov 8 21:26:06 1998 @@ -7,6 +7,8 @@ /***********************************************************************/ /***********************************************************************/ /* $Id: polarit1.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" GEN sort_factor(GEN y); GEN make_base(long n, GEN base); diff -pru ./src.ini/basemath/polarit2.c ./src/basemath/polarit2.c --- ./src.ini/basemath/polarit2.c Fri Nov 6 10:08:22 1998 +++ ./src/basemath/polarit2.c Sun Nov 8 21:26:06 1998 @@ -7,6 +7,8 @@ /***********************************************************************/ /***********************************************************************/ /* $Id: polarit2.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" GEN diff -pru ./src.ini/basemath/polarit3.c ./src/basemath/polarit3.c --- ./src.ini/basemath/polarit3.c Fri Nov 6 10:08:30 1998 +++ ./src/basemath/polarit3.c Sun Nov 8 21:26:06 1998 @@ -7,6 +7,8 @@ /***********************************************************************/ /***********************************************************************/ /* $Id: polarit3.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" /*******************************************************************/ diff -pru ./src.ini/basemath/rootpol.c ./src/basemath/rootpol.c --- ./src.ini/basemath/rootpol.c Fri Nov 6 10:08:22 1998 +++ ./src/basemath/rootpol.c Sun Nov 8 21:26:06 1998 @@ -7,6 +7,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: rootpol.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #define pariINFINITY 100000 diff -pru ./src.ini/basemath/trans1.c ./src/basemath/trans1.c --- ./src.ini/basemath/trans1.c Fri Nov 6 12:50:10 1998 +++ ./src/basemath/trans1.c Sun Nov 8 21:26:06 1998 @@ -6,6 +6,8 @@ /********************************************************************/ /********************************************************************/ /* $Id: trans1.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #ifdef LONG_IS_64BIT diff -pru ./src.ini/basemath/trans2.c ./src/basemath/trans2.c --- ./src.ini/basemath/trans2.c Fri Nov 6 10:08:26 1998 +++ ./src/basemath/trans2.c Sun Nov 8 21:26:06 1998 @@ -7,6 +7,8 @@ /********************************************************************/ /********************************************************************/ /* $Id: trans2.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" GEN mpsin(GEN x); diff -pru ./src.ini/basemath/trans3.c ./src/basemath/trans3.c --- ./src.ini/basemath/trans3.c Fri Nov 6 10:08:26 1998 +++ ./src/basemath/trans3.c Sun Nov 8 21:26:06 1998 @@ -7,6 +7,8 @@ /********************************************************************/ /********************************************************************/ /* $Id: trans3.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" /***********************************************************************/ diff -pru ./src.ini/gp/gp.c ./src/gp/gp.c --- ./src.ini/gp/gp.c Sun Nov 8 04:22:06 1998 +++ ./src/gp/gp.c Sun Nov 8 21:26:16 1998 @@ -4,6 +4,8 @@ /** **/ /*******************************************************************/ /* $Id: gp.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #ifdef _WIN32 # include <windows.h> diff -pru ./src.ini/gp/gp_init.c ./src/gp/gp_init.c --- ./src.ini/gp/gp_init.c Fri Nov 6 10:08:34 1998 +++ ./src/gp/gp_init.c Sun Nov 8 21:26:16 1998 @@ -4,6 +4,8 @@ /* */ /*******************************************************************/ /* $Id: gp_init.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "../graph/rect.h" diff -pru ./src.ini/gp/gp_rl.c ./src/gp/gp_rl.c --- ./src.ini/gp/gp_rl.c Sun Nov 8 04:22:06 1998 +++ ./src/gp/gp_rl.c Sun Nov 8 21:26:16 1998 @@ -6,6 +6,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: gp_rl.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "../language/anal.h" #include "gp.h" diff -pru ./src.ini/graph/plotgnuplot.c ./src/graph/plotgnuplot.c --- ./src.ini/graph/plotgnuplot.c Sun Nov 8 04:22:06 1998 +++ ./src/graph/plotgnuplot.c Sun Nov 8 21:44:32 1998 @@ -9,7 +9,9 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: plotgnuplot.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ -# include "pari.h" + +#define PARI_OLD_GEN +#include "pari.h" #include "rect.h" #define croak(str) err(talker,str) #include "Gnuplot.h" diff -pru ./src.ini/graph/plotnull.c ./src/graph/plotnull.c --- ./src.ini/graph/plotnull.c Fri Nov 6 10:08:44 1998 +++ ./src/graph/plotnull.c Sun Nov 8 21:26:24 1998 @@ -1,4 +1,6 @@ /* $Id: plotnull.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" void diff -pru ./src.ini/graph/plotport.c ./src/graph/plotport.c --- ./src.ini/graph/plotport.c Sun Nov 8 17:56:08 1998 +++ ./src/graph/plotport.c Sun Nov 8 21:26:24 1998 @@ -6,6 +6,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: plotport.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "rect.h" diff -pru ./src.ini/graph/plotsun.c ./src/graph/plotsun.c --- ./src.ini/graph/plotsun.c Sun Nov 8 04:22:06 1998 +++ ./src/graph/plotsun.c Sun Nov 8 21:26:24 1998 @@ -6,6 +6,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: plotsun.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "rect.h" #include <suntool/sunview.h> diff -pru ./src.ini/graph/plotX.c ./src/graph/plotX.c --- ./src.ini/graph/plotX.c Sun Nov 8 04:22:06 1998 +++ ./src/graph/plotX.c Sun Nov 8 21:26:24 1998 @@ -6,6 +6,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: plotX.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "rect.h" #include "../language/anal.h" diff -pru ./src.ini/kernel/none/level0.c ./src/kernel/none/level0.c --- ./src.ini/kernel/none/level0.c Thu Jul 23 08:40:28 1998 +++ ./src/kernel/none/level0.c Sun Nov 8 21:25:36 1998 @@ -1,2 +1,4 @@ #define LEVEL0 + +#define PARI_OLD_GEN #include "pari.h" diff -pru ./src.ini/kernel/none/level1.c ./src/kernel/none/level1.c --- ./src.ini/kernel/none/level1.c Fri Nov 6 10:08:34 1998 +++ ./src/kernel/none/level1.c Sun Nov 8 21:25:36 1998 @@ -1,3 +1,5 @@ /* $Id: level1.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ #define LEVEL1 + +#define PARI_OLD_GEN #include "pari.h" diff -pru ./src.ini/kernel/none/level1.h ./src/kernel/none/level1.h --- ./src.ini/kernel/none/level1.h Fri Nov 6 10:08:34 1998 +++ ./src/kernel/none/level1.h Sun Nov 8 23:11:22 1998 @@ -18,9 +18,9 @@ void addsii(long x, GEN y, GEN z); long addssmod(long a, long b, long p); void addssz(long x, long y, GEN z); -void affii(GEN x, GEN y); -void affsi(long s, GEN x); -void affsr(long s, GEN x); +void affii(valINT *x, valINT *y); +void affsi(long s, valINT *x); +void affsr(long s, valREAL *x); GEN cgetg(long x, long y); GEN cgeti(long x); GEN cgetr(long x); @@ -46,7 +46,7 @@ long expi(GEN x); #endif double gtodouble(GEN x); GEN icopy(GEN x); -long itos(GEN x); +long itos(valINT *x); GEN modis(GEN x, long y); GEN mpabs(GEN x); GEN mpadd(GEN x, GEN y); @@ -113,7 +113,7 @@ INLINE GEN cgetg(long x, long y) { const GEN z = new_chunk(x); - z[0] = evaltyp(y) | evallg(x); + GENheader(z) = evaltyp(y) | evallg(x); return z; } @@ -121,7 +121,7 @@ INLINE GEN cgeti(long x) { const GEN z = new_chunk(x); - z[0] = evaltyp(t_INT) | evallg(x); + GENheader(z) = evaltyp(t_INT) | evallg(x); return z; } @@ -129,7 +129,7 @@ INLINE GEN cgetr(long x) { const GEN z = new_chunk(x); - z[0] = evaltyp(t_REAL) | evallg(x); + GENheader(z) = evaltyp(t_REAL) | evallg(x); return z; } # endif /* __M68K__ */ @@ -192,57 +192,57 @@ stoi(long x) } INLINE long -itos(GEN x) +itos(valINT *x) { const long s=signe(x); long p1; if (!s) return 0; if (lgefint(x)>3) err(affer2); - p1=x[2]; if (p1 < 0) err(affer2); + p1 = valINTbuffer(x,0); if (p1 < 0) err(affer2); return (s>0) ? p1 : -(long)p1; } INLINE void -affii(GEN x, GEN y) +affii(valINT *x, valINT *y) { long lx; if (x==y) return; lx=lgefint(x); if (lg(y)<lx) err(affer3); - while (--lx) y[lx]=x[lx]; + while (--lx) valINTbuffer(y, lx - 2) = valINTbuffer(x, lx-2); } INLINE void -affsi(long s, GEN x) +affsi(long s, valINT *x) { - if (!s) { x[1]=2; return; } + if (!s) { GENdescr(x) = 2; return; } if (lg(x)<3) err(affer1); - if (s>0) { x[1] = evalsigne(1) | evallgefint(3); x[2] = s; } - else { x[1] = evalsigne(-1) | evallgefint(3); x[2] = -s; } + if (s>0) { GENdescr(x) = evalsigne(1) | evallgefint(3); valINTbuffer(x,0) = s; } + else { GENdescr(x) = evalsigne(-1) | evallgefint(3); valINTbuffer(x,0) = -s; } } INLINE void -affsr(long s, GEN x) +affsr(long s, valREAL *x) { long l; if (!s) { l = -bit_accuracy(lg(x)); - x[1]=evalexpo(l); x[2]=0; return; + GENdescr(x)=evalexpo(l); valINTbuffer(x,0)=0; return; } - if (s<0) { x[1] = evalsigne(-1); s = -s; } - else x[1] = evalsigne(1); - l=bfffo(s); x[1] |= evalexpo((BITS_IN_LONG-1)-l); - x[2] = s<<l; for (l=3; l<lg(x); l++) x[l]=0; + if (s<0) { GENdescr(x) = evalsigne(-1); s = -s; } + else GENdescr(x) = evalsigne(1); + l=bfffo(s); GENdescr(x) |= evalexpo((BITS_IN_LONG-1)-l); + valINTbuffer(x,0) = s<<l; for (l=3; l<lg(x); l++) valINTbuffer(x,l-2)=0; } INLINE void mpaff(GEN x, GEN y) { if (typ(x)==t_INT) - { if (typ(y)==t_INT) affii(x,y); else affir(x,y); } + { if (typ(y)==t_INT) affii((valINT *)x,(valINT *)y); else affir(x,y); } else { if (typ(y)==t_INT) affri(x,y); else affrr(x,y); } } @@ -254,7 +254,7 @@ shiftr(GEN x, long n) const GEN y = rcopy(x); if (e & ~EXPOBITS) err(shier2); - y[1] = (y[1]&~EXPOBITS) | e; return y; + GENdescr(y) = (GENdescr(y)&~EXPOBITS) | e; return y; } INLINE int @@ -272,11 +272,11 @@ INLINE int cmpsr(long x, GEN y) { long av; - GEN z; + valREAL *z; if (!x) return -signe(y); - av=avma; z=cgetr(3); affsr(x,z); avma=av; - return cmprr(z,y); + av=avma; z = NEWvalREAL(1); affsr(x,z); avma=av; + return cmprr((GEN)z,y); } INLINE void @@ -286,9 +286,9 @@ addssz(long x, long y, GEN z) else { const long av=avma; - const GEN p1=cgetr(lg(z)); + valREAL * const p1=NEWvalREAL(lg(z) - 2); - affsr(x,p1); affrr(addrs(p1,y),z); avma=av; + affsr(x,p1); affrr(addrs((GEN)p1,y),(GEN)z); avma=av; } } @@ -361,31 +361,31 @@ mulssz(long x, long y, GEN z) else { const long av=avma; - const GEN p1=cgetr(lg(z)); + valREAL * const p1 = NEWvalREAL(lg(z) - 2); - affsr(x,p1); mpaff(mulsr(y,p1),z); avma=av; + affsr(x,p1); mpaff(mulsr(y,(GEN)p1),(GEN)z); avma=av; } } INLINE void -mulsii(long x, GEN y, GEN z) +mulsii(long x, GEN y, valINT *z) { const long av=avma; - affii(mulsi(x,y),z); avma=av; + affii((valINT *)mulsi(x,y),z); avma=av; } INLINE void -addsii(long x, GEN y, GEN z) +addsii(long x, GEN y, valINT *z) { const long av=avma; - affii(addsi(x,y),z); avma=av; + affii((valINT *)addsi(x,y),z); avma=av; } INLINE long -divisii(GEN x, long y, GEN z) +divisii(GEN x, long y, valINT *z) { const long av=avma; - affii(divis(x,y),z); avma=av; return hiremainder; + affii((valINT *)divis(x,y),z); avma=av; return hiremainder; } INLINE long @@ -395,8 +395,8 @@ vali(GEN x) if (!signe(x)) return -1; lx = lgefint(x)-1; - i=lx; while (i>=2 && !x[i]) i--; - return ((lx-i)<<TWOPOTBITS_IN_LONG) + vals(x[i]); + i=lx; while (i>=2 && !valINTbuffer(x,i-2)) i--; + return ((lx-i)<<TWOPOTBITS_IN_LONG) + vals(valINTbuffer(x,i-2)); } INLINE GEN @@ -434,7 +434,7 @@ dvmdis(GEN x, long y, GEN *z) } INLINE void -dvmdssz(long x, long y, GEN z, GEN t) +dvmdssz(long x, long y, GEN z, valINT *t) { const long av=avma; const GEN p1=divss(x,y); @@ -443,7 +443,7 @@ dvmdssz(long x, long y, GEN z, GEN t) } INLINE void -dvmdsiz(long x, GEN y, GEN z, GEN t) +dvmdsiz(long x, GEN y, GEN z, valINT *t) { const long av=avma; const GEN p1=divsi(x,y); @@ -452,7 +452,7 @@ dvmdsiz(long x, GEN y, GEN z, GEN t) } INLINE void -dvmdisz(GEN x, long y, GEN z, GEN t) +dvmdisz(GEN x, long y, GEN z, valINT *t) { const long av=avma; const GEN p1=divis(x,y); @@ -511,10 +511,11 @@ divsiz(long x, GEN y, GEN z) else { const long lz=lg(z); - const GEN p1=cgetr(lz), p2=cgetr(lz); + valREAL * const p1 = NEWvalREAL(lz - 2); + valREAL * const p2 = NEWvalREAL(lz - 2); - affsr(x,p1); affir(y,p2); - affrr(divrr(p1,p2),z); + affsr(x,p1); affir(y,(GEN)p2); + affrr(divrr((GEN)p1,(GEN)p2),z); } avma=av; } @@ -527,9 +528,9 @@ divssz(long x, long y, GEN z) if (typ(z)==t_INT) gaffect(divss(x,y),z); else { - const GEN p1=cgetr(lg(z)); + valREAL * const p1 = NEWvalREAL(lg(z) - 2); - affsr(x,p1); affrr(divrs(p1,y),z); + affsr(x,p1); affrr(divrs((GEN)p1,y),z); } avma=av; } @@ -542,10 +543,10 @@ divrrz(GEN x, GEN y, GEN z) } INLINE void -resiiz(GEN x, GEN y, GEN z) +resiiz(GEN x, GEN y, valINT *z) { const long av=avma; - affii(resii(x,y),z); avma=av; + affii((valINT *)resii(x,y),z); avma=av; } INLINE int @@ -598,14 +599,14 @@ mpdiv(GEN x, GEN y) } INLINE int -mpdivis(GEN x, GEN y, GEN z) +mpdivis(GEN x, GEN y, valINT* z) { const long av=avma; GEN p2; const GEN p1=dvmdii(x,y,&p2); if (signe(p2)) { avma=av; return 0; } - affii(p1,z); avma=av; return 1; + affii((valINT *)p1,z); avma=av; return 1; } /* THE FOLLOWING ONES ARE NOT IN mp.s */ @@ -667,7 +668,7 @@ INLINE long expi(GEN x) { const long lx=lgefint(x); - return lx==2? -HIGHEXPOBIT: bit_accuracy(lx)-bfffo(x[2])-1; + return lx==2? -HIGHEXPOBIT: bit_accuracy(lx)-bfffo(valINTbuffer(x,0))-1; } #endif diff -pru ./src.ini/kernel/none/mp.c ./src/kernel/none/mp.c --- ./src.ini/kernel/none/mp.c Fri Nov 6 10:08:36 1998 +++ ./src/kernel/none/mp.c Sun Nov 8 21:25:36 1998 @@ -6,6 +6,8 @@ /***********************************************************************/ /***********************************************************************/ /* $Id: mp.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #if 0 /* for tests on a specific broken machine! */ char *xmalloc(long x) { return malloc(x); } diff -pru ./src.ini/language/anal.c ./src/language/anal.c --- ./src.ini/language/anal.c Fri Nov 6 13:21:42 1998 +++ ./src/language/anal.c Sun Nov 8 21:26:30 1998 @@ -6,6 +6,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: anal.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "anal.h" #include "parinf.h" diff -pru ./src.ini/language/compat.c ./src/language/compat.c --- ./src.ini/language/compat.c Fri Nov 6 10:09:00 1998 +++ ./src/language/compat.c Sun Nov 8 21:26:30 1998 @@ -1,4 +1,6 @@ /* $Id: compat.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" GEN geni(void); diff -pru ./src.ini/language/es.c ./src/language/es.c --- ./src.ini/language/es.c Sun Nov 8 04:22:08 1998 +++ ./src/language/es.c Sun Nov 8 21:26:30 1998 @@ -4,6 +4,8 @@ /** **/ /*******************************************************************/ /* $Id: es.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "anal.h" GEN confrac(GEN x); /* should be static here, but use hiremainder */ diff -pru ./src.ini/language/highlvl.c ./src/language/highlvl.c --- ./src.ini/language/highlvl.c Sun Nov 8 04:22:08 1998 +++ ./src/language/highlvl.c Sun Nov 8 21:26:30 1998 @@ -4,6 +4,8 @@ /* */ /*******************************************************************/ /* $Id: highlvl.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "../graph/rect.h" #include "../language/anal.h" diff -pru ./src.ini/language/init.c ./src/language/init.c --- ./src.ini/language/init.c Sun Nov 8 04:22:08 1998 +++ ./src/language/init.c Sun Nov 8 21:26:30 1998 @@ -7,6 +7,8 @@ /*******************************************************************/ /* $Id: init.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ #include <string.h> + +#define PARI_OLD_GEN #include "pari.h" #include "anal.h" #ifdef _WIN32 diff -pru ./src.ini/language/sumiter.c ./src/language/sumiter.c --- ./src.ini/language/sumiter.c Fri Nov 6 10:08:56 1998 +++ ./src/language/sumiter.c Sun Nov 8 21:26:30 1998 @@ -7,6 +7,8 @@ /********************************************************************/ /********************************************************************/ /* $Id: sumiter.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include "anal.h" diff -pru ./src.ini/modules/elliptic.c ./src/modules/elliptic.c --- ./src.ini/modules/elliptic.c Fri Nov 6 10:09:08 1998 +++ ./src/modules/elliptic.c Sun Nov 8 21:14:58 1998 @@ -6,6 +6,8 @@ /********************************************************************/ /********************************************************************/ /* $Id: elliptic.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" void diff -pru ./src.ini/modules/galois.c ./src/modules/galois.c --- ./src.ini/modules/galois.c Fri Nov 6 10:09:00 1998 +++ ./src/modules/galois.c Sun Nov 8 21:15:22 1998 @@ -4,6 +4,8 @@ /* */ /**************************************************************/ /* $Id: galois.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #include <fcntl.h> diff -pru ./src.ini/modules/kummer.c ./src/modules/kummer.c --- ./src.ini/modules/kummer.c Fri Nov 6 10:09:02 1998 +++ ./src/modules/kummer.c Sun Nov 8 21:15:28 1998 @@ -6,6 +6,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: kummer.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" static long rc,gc,ell,degK,degKz,m,d,ru,rv,lraycyc,vnf,dv,nbcol,lSml2; diff -pru ./src.ini/modules/mpqs.c ./src/modules/mpqs.c --- ./src.ini/modules/mpqs.c Fri Nov 6 10:09:04 1998 +++ ./src/modules/mpqs.c Sun Nov 8 21:15:36 1998 @@ -29,6 +29,8 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* $Id: mpqs.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #ifndef SEEK_SET diff -pru ./src.ini/modules/nffactor.c ./src/modules/nffactor.c --- ./src.ini/modules/nffactor.c Fri Nov 6 10:09:04 1998 +++ ./src/modules/nffactor.c Sun Nov 8 21:15:40 1998 @@ -7,6 +7,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: nffactor.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" /* rnfminpoly PAS ENCORE UTILISE */ diff -pru ./src.ini/modules/stark.c ./src/modules/stark.c --- ./src.ini/modules/stark.c Fri Nov 6 10:09:06 1998 +++ ./src/modules/stark.c Sun Nov 8 21:15:10 1998 @@ -7,6 +7,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: stark.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" /********************************************************************/ diff -pru ./src.ini/modules/subfield.c ./src/modules/subfield.c --- ./src.ini/modules/subfield.c Fri Nov 6 10:09:06 1998 +++ ./src/modules/subfield.c Sun Nov 8 21:15:48 1998 @@ -8,6 +8,8 @@ /*******************************************************************/ /*******************************************************************/ /* $Id: subfield.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" #ifdef __WIN32 # include <io.h> /* for open, read, close */ diff -pru ./src.ini/modules/thue.c ./src/modules/thue.c --- ./src.ini/modules/thue.c Fri Nov 6 10:09:06 1998 +++ ./src/modules/thue.c Sun Nov 8 21:15:54 1998 @@ -5,6 +5,8 @@ * The last part of the program (bnfisintnorm) was written by K. Belabas. */ /* $Id: thue.c,v 2.0.12.7 1998/11/06 15:07:57 belabas Exp belabas $ */ + +#define PARI_OLD_GEN #include "pari.h" static int curne,r,s,t,deg,Prec,ConstPrec,numroot; --- ./examples/matexp.c.bak Thu Jul 23 08:40:00 1998 +++ ./examples/matexp.c Sun Nov 8 23:26:16 1998 @@ -1,38 +1,42 @@ +#define PARI_OLD_GENx #include "pari.h" GEN -matexp(GEN x,long prec) +matexp(valMAT *x,long prec) { long lx=lg(x),i,k,n, ltop = avma; - GEN y,r,s,p1,p2; + GEN y,s,p1,p2; + valREAL *r; /* check that x is a square matrix */ if (typ(x) != t_MAT) err(typeer,"matexp"); if (lx == 1) return cgetg(1, t_MAT); - if (lx != lg(x[1])) err(talker,"not a square matrix"); - + if (lx != lg(x->elt[0])) err(talker,"not a square matrix"); + lx--; + /* convert x to real or complex of real and compute its L2 norm */ - s = gzero; r = cgetr(prec+1); affsr(1,r); x = gmul(r,x); - for (i=1; i<lx; i++) - s = gadd(s, gnorml2((GEN)x[i])); + s = gzero; r = NEWvalREAL(prec-1); affsr(1,r); + x = (valMAT*)gmul((GEN)r,(GEN)x); + for (i=0; i<lx; i++) + s = gadd(s, gnorml2((GEN)x->elt[i])); if (typ(s) == t_REAL) setlg(s,3); s = gsqrt(s,3); /* we do not need much precision on s */ /* if s<1 we are happy */ k = expo(s); - if (k < 0) { n = 0; p1 = x; } - else { n = k+1; p1 = gmul2n(x,-n); setexpo(s,-1); } + if (k < 0) { n = 0; p1 = (GEN)x; } + else { n = k+1; p1 = gmul2n((GEN)x,-n); setexpo(s,-1); } /* initializations before the loop */ - y = gscalmat(r,lx-1); /* creates scalar matrix with r on diagonal */ - p2 = p1; r = s; k = 1; + y = gscalmat((GEN)r,lx); /* creates scalar matrix with r on diagonal */ + p2 = p1; r = (valREAL *)s; k = 1; y = gadd(y,p2); /* now the main loop */ while (expo(r) >= -BITS_IN_LONG*(prec-1)) { k++; p2 = gdivgs(gmul(p2,p1),k); - r = gdivgs(gmul(s,r),k); y = gadd(y,p2); + r = (valREAL *)gdivgs(gmul(s,(GEN)r),k); y = gadd(y,p2); } /* now square back n times if necessary */ @@ -49,11 +53,11 @@ main() /* take a stack of 10^6 bytes, no prime table */ pari_init(1000000, 2); printf("precision of the computation in decimal digits:\n"); - d = itos(lisGEN(stdin)); + d = itos((valINT *)lisGEN(stdin)); if (d > 0) prec = (long)(d*pariK1+3); printf("input your matrix in GP format:\n"); - x = matexp(lisGEN(stdin), prec); + x = matexp((valMAT *)lisGEN(stdin), prec); sor(x, 'g', d, 0); exit(0);