=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/io/pexpr.c,v retrieving revision 1.3 retrieving revision 1.14 diff -u -p -r1.3 -r1.14 --- OpenXM_contrib2/asir2000/io/pexpr.c 2000/08/21 08:31:38 1.3 +++ OpenXM_contrib2/asir2000/io/pexpr.c 2001/08/06 01:48:33 1.14 @@ -23,7 +23,7 @@ * shall be made on your publication or presentation in any form of the * results obtained by use of the SOFTWARE. * (4) In the event that you modify the SOFTWARE, you shall notify FLL by - * e-mail at risa-admin@flab.fujitsu.co.jp of the detailed specification + * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification * for such modification or the source code of the modified part of the * SOFTWARE. * @@ -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.2 2000/02/07 03:14:39 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/io/pexpr.c,v 1.13 2001/04/20 02:34:23 noro Exp $ */ #include "ca.h" #include "al.h" @@ -64,6 +64,9 @@ FILE *asir_out; char DFORMAT[BUFSIZ]; int hex_output; int fortran_output; +int double_output; +int real_digit; +int print_quote; #define TAIL #define PUTS(s) fputs(s,OUT) @@ -87,6 +90,8 @@ int fortran_output; #define PRINTUI printui #define PRINTGF2MAT printgf2mat #define PRINTGFMMAT printgfmmat +#define PRINTBYTEARRAY printbytearray +#define PRINTQUOTE printquote #define PRINTERR printerr #define PRINTLF printlf #define PRINTLOP printlop @@ -102,6 +107,9 @@ static char *buf; extern char DFORMAT[BUFSIZ]; extern int hex_output; extern int fortran_output; +extern int double_output; +extern int real_digit; +extern int print_quote; #define TAIL while ( *OUT ) OUT++; #define PUTS(s) strcat(OUT,s) @@ -125,6 +133,8 @@ extern int fortran_output; #define PRINTUI sprintui #define PRINTGF2MAT sprintgf2mat #define PRINTGFMMAT sprintgfmmat +#define PRINTBYTEARRAY sprintbytearray +#define PRINTQUOTE sprintquote #define PRINTERR sprinterr #define PRINTLF sprintlf #define PRINTLOP sprintlop @@ -149,6 +159,8 @@ void PRINTDP(); void PRINTUI(); void PRINTGF2MAT(); void PRINTGFMMAT(); +void PRINTBYTEARRAY(); +void PRINTQUOTE(); void PRINTERR(); void PRINTCPLX(); void PRINTLM(); @@ -165,7 +177,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 +196,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 +209,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 +275,10 @@ Obj p; PRINTLF(vl,(F)p); break; case O_GFMMAT: PRINTGFMMAT(vl,(GFMMAT)p); break; + case O_BYTEARRAY: + PRINTBYTEARRAY(vl,(BYTEARRAY)p); break; + case O_QUOTE: + PRINTQUOTE(vl,(QUOTE)p); break; default: break; } @@ -281,9 +315,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 +362,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 +391,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 +437,9 @@ Num q; case N_GFPN: PRINTUP((UP)(((GFPN)q)->body)); break; + case N_GFS: + TAIL PRINTF(OUT,"@_%d",CONT((GFS)q)); + break; } } @@ -332,7 +450,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"); } @@ -611,6 +735,38 @@ GFMMAT mat; TAIL PRINTF(OUT,"%8d",b[i][j]); } 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 PRINTQUOTE(vl,quote) +VL vl; +QUOTE quote; +{ + LIST list; + + if ( print_quote ) { + fnodetotree(BDY(quote),&list); + PRINTEXPR(vl,(Obj)list); + } else { + PUTS("<...quoted...>"); } }