=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/io/pexpr.c,v retrieving revision 1.4 retrieving revision 1.11 diff -u -p -r1.4 -r1.11 --- OpenXM_contrib2/asir2000/io/pexpr.c 2000/08/22 05:04:18 1.4 +++ OpenXM_contrib2/asir2000/io/pexpr.c 2001/03/13 01:10:27 1.11 @@ -44,7 +44,7 @@ * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. - * $OpenXM: OpenXM_contrib2/asir2000/io/pexpr.c,v 1.3 2000/08/21 08:31:38 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/io/pexpr.c,v 1.10 2001/03/09 01:44:10 noro Exp $ */ #include "ca.h" #include "al.h" @@ -64,6 +64,8 @@ FILE *asir_out; char DFORMAT[BUFSIZ]; int hex_output; int fortran_output; +int double_output; +int real_digit; #define TAIL #define PUTS(s) fputs(s,OUT) @@ -87,6 +89,7 @@ int fortran_output; #define PRINTUI printui #define PRINTGF2MAT printgf2mat #define PRINTGFMMAT printgfmmat +#define PRINTBYTEARRAY printbytearray #define PRINTERR printerr #define PRINTLF printlf #define PRINTLOP printlop @@ -125,6 +128,7 @@ extern int fortran_output; #define PRINTUI sprintui #define PRINTGF2MAT sprintgf2mat #define PRINTGFMMAT sprintgfmmat +#define PRINTBYTEARRAY sprintbytearray #define PRINTERR sprinterr #define PRINTLF sprintlf #define PRINTLOP sprintlop @@ -149,6 +153,7 @@ void PRINTDP(); void PRINTUI(); void PRINTGF2MAT(); void PRINTGFMMAT(); +void PRINTBYTEARRAY(); void PRINTERR(); void PRINTCPLX(); void PRINTLM(); @@ -165,7 +170,12 @@ int mmono(p) P p; { if ( NUM(p) ) +#if defined(INTERVAL) + if ( NID(p) != N_IP && NID(p) != N_ID && NID(p) != N_IT && NID(p) != N_IF + && compnum(CO,(Num)p,0) < 0 ) +#else if ( compnum(CO,(Num)p,0) < 0 ) +#endif return ( 1 ); else return ( 0 ); @@ -179,7 +189,7 @@ P p; void printbf(a) BF a; { - sor(a->body,'g',-1,0); + sor(a->body,double_output ? 'f' : 'g',-1,0); } #endif #endif @@ -192,13 +202,26 @@ char *s; } #if PARI +#include "genpari.h" + +void myoutbrute(g) +GEN g; +{ + bruteall(g,'f',-1,1); +} + void sprintbf(a) BF a; { char *str; char *GENtostr(); + char *GENtostr0(); - str = GENtostr(a->body); + if ( double_output ) { + str = GENtostr0(a->body,myoutbrute); + } else { + str = GENtostr(a->body); + } TAIL PRINTF(OUT,"%s",str); free(str); } @@ -245,6 +268,8 @@ Obj p; PRINTLF(vl,(F)p); break; case O_GFMMAT: PRINTGFMMAT(vl,(GFMMAT)p); break; + case O_BYTEARRAY: + PRINTBYTEARRAY(vl,(BYTEARRAY)p); break; default: break; } @@ -281,9 +306,39 @@ N n; } } +#if defined(ITVDEBUG) +void printbin(double z) +{ + int i, j, mask; + union { + double x; + char c[8]; + } a; + + a.x = z; + for(i=7;i>=0;i--) { + mask = 0x80; + for(j=0;j<8;j++) { + if (a.c[i] & mask) fprintf(stderr,"1"); + else fprintf(stderr,"0"); + mask >>= 1; + } + } + fprintf(stderr,"\n"); +} +#endif + +#if 0 +int printmode = PRINTF_E; +#else +int printmode = PRINTF_G; +#endif + void PRINTNUM(q) Num q; { + char real_format[20]; + if ( !q ) { PUTS("0"); return; @@ -298,7 +353,27 @@ Num q; } break; case N_R: - TAIL PRINTF(OUT,"%g",BDY((Real)q)); + switch (printmode) { + case PRINTF_E: +#if defined(INTERVAL) + case MID_PRINTF_E: +#endif + TAIL PRINTF(OUT,"%.16e",BDY((Real)q)); + break; + case PRINTF_G: +#if defined(INTERVAL) + case MID_PRINTF_G: +#endif + default: + if ( real_digit ) { + sprintf(real_format, + double_output?"%%.%df":"%%.%dg",real_digit); + TAIL PRINTF(OUT,real_format,BDY((Real)q)); + } else { + TAIL PRINTF(OUT,double_output?"%f":"%g",BDY((Real)q)); + } + break; + } break; case N_A: PUTS("("); PRINTR(ALG,(R)BDY((Alg)q)); PUTS(")"); @@ -307,6 +382,37 @@ Num q; case N_B: PRINTBF((BF)q); break; #endif +#if defined(INTERVAL) + case N_IP: + case N_IF: + PUTS("["); + PRINTNUM(INF((Itv)q)); + PUTS(","); + PRINTNUM(SUP((Itv)q)); + PUTS("]"); + break; + case N_ID: + switch (printmode) { + case PRINTF_E: + TAIL PRINTF(OUT, "[%.16e,%.16e]",INF((ItvD)q),SUP((ItvD)q)); +#if defined(ITVDEBUG) + printbin(INF((ItvD)q)); + printbin(SUP((ItvD)q)); +#endif + break; + case MID_PRINTF_G: + TAIL PRINTF(OUT, "<%g,%g>", (SUP((ItvD)q)+INF((ItvD)q))*0.5,(SUP((ItvD)q)-INF((ItvD)q))*0.5); + break; + case MID_PRINTF_E: + TAIL PRINTF(OUT, "<%.16e,%.16e>", (SUP((ItvD)q)+INF((ItvD)q))*0.5,(SUP((ItvD)q)-INF((ItvD)q))*0.5); + break; + case PRINTF_G: + default: + TAIL PRINTF(OUT, "[%g,%g]",INF((ItvD)q),SUP((ItvD)q)); + break; + } + break; +#endif case N_C: PRINTCPLX((C)q); break; case N_M: @@ -322,6 +428,9 @@ Num q; case N_GFPN: PRINTUP((UP)(((GFPN)q)->body)); break; + case N_GFS: + TAIL PRINTF(OUT,"%d",CONT((GFS)q)); break; + break; } } @@ -332,7 +441,13 @@ C a; if ( a->r ) PRINTNUM(a->r); if ( a->i ) { +#if defined(INTERVAL) + if ( a->r && ((compnum(0,a->i,0) > 0) + || NID(a->i) == N_IP || NID(a->i) == N_ID + || NID(a->i) == N_IT || NID(a->i) == N_IF) ) +#else if ( a->r && (compnum(0,a->i,0) > 0) ) +#endif PUTS("+"); PRINTNUM(a->i); PUTS("*@i"); } @@ -612,6 +727,24 @@ GFMMAT mat; } PUTS("]\n"); } +} + +void PRINTBYTEARRAY(vl,array) +VL vl; +BYTEARRAY array; +{ + int len,i; + unsigned int t; + unsigned char *b; + + len = array->len; + b = array->body; + PUTS("|"); + for ( i = 0; i < len-1; i++ ) { + TAIL PRINTF(OUT,"%02x ",(unsigned int)b[i]); + } + TAIL PRINTF(OUT,"%02x",(unsigned int)b[i]); + PUTS("|"); } void PRINTERR(vl,e)