=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/io/pexpr.c,v retrieving revision 1.5 retrieving revision 1.13 diff -u -p -r1.5 -r1.13 --- OpenXM_contrib2/asir2000/io/pexpr.c 2000/11/08 08:02:51 1.5 +++ OpenXM_contrib2/asir2000/io/pexpr.c 2001/04/20 02:34:23 1.13 @@ -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.4 2000/08/22 05:04:18 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/io/pexpr.c,v 1.12 2001/03/15 05:52:12 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) @@ -88,6 +90,7 @@ int fortran_output; #define PRINTGF2MAT printgf2mat #define PRINTGFMMAT printgfmmat #define PRINTBYTEARRAY printbytearray +#define PRINTQUOTE printquote #define PRINTERR printerr #define PRINTLF printlf #define PRINTLOP printlop @@ -127,6 +130,7 @@ extern int fortran_output; #define PRINTGF2MAT sprintgf2mat #define PRINTGFMMAT sprintgfmmat #define PRINTBYTEARRAY sprintbytearray +#define PRINTQUOTE sprintquote #define PRINTERR sprinterr #define PRINTLF sprintlf #define PRINTLOP sprintlop @@ -152,6 +156,7 @@ void PRINTUI(); void PRINTGF2MAT(); void PRINTGFMMAT(); void PRINTBYTEARRAY(); +void PRINTQUOTE(); void PRINTERR(); void PRINTCPLX(); void PRINTLM(); @@ -168,7 +173,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 ); @@ -182,7 +192,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 @@ -195,13 +205,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); } @@ -250,6 +273,8 @@ Obj p; PRINTGFMMAT(vl,(GFMMAT)p); break; case O_BYTEARRAY: PRINTBYTEARRAY(vl,(BYTEARRAY)p); break; + case O_QUOTE: + PRINTQUOTE(vl,(QUOTE)p); break; default: break; } @@ -286,9 +311,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; @@ -303,7 +358,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(")"); @@ -312,6 +387,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: @@ -327,6 +433,9 @@ Num q; case N_GFPN: PRINTUP((UP)(((GFPN)q)->body)); break; + case N_GFS: + TAIL PRINTF(OUT,"@_%d",CONT((GFS)q)); break; + break; } } @@ -337,7 +446,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"); } @@ -635,6 +750,13 @@ BYTEARRAY array; } TAIL PRINTF(OUT,"%02x",(unsigned int)b[i]); PUTS("|"); +} + +void PRINTQUOTE(vl,quote) +VL vl; +QUOTE quote; +{ + PUTS("<...quoted...>"); } void PRINTERR(vl,e)