=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/io/spexpr.c,v retrieving revision 1.25 retrieving revision 1.28 diff -u -p -r1.25 -r1.28 --- OpenXM_contrib2/asir2000/io/spexpr.c 2003/12/25 02:40:24 1.25 +++ OpenXM_contrib2/asir2000/io/spexpr.c 2004/02/13 05:48:36 1.28 @@ -44,14 +44,15 @@ * 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/spexpr.c,v 1.24 2003/06/09 16:18:10 saito Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/io/spexpr.c,v 1.27 2004/02/09 08:23:30 noro Exp $ */ #include "ca.h" #include "al.h" #include "parse.h" #include "comp.h" #include "base.h" -#if PARI + +#if defined(PARI) #include "genpari.h" #endif @@ -70,6 +71,7 @@ int hex_output; int fortran_output; int double_output; int real_digit; +int real_binary; int print_quote; #define TAIL @@ -105,6 +107,8 @@ int print_quote; #define PRINTUP printup #define PRINTUM printum #define PRINTSF printsf +#define PRINTSYMBOL printsymbol +#define PRINTRANGE printrange #endif #ifdef SPRINT @@ -115,6 +119,7 @@ extern int hex_output; extern int fortran_output; extern int double_output; extern int real_digit; +extern int real_binary; extern int print_quote; @@ -151,6 +156,8 @@ extern int print_quote; #define PRINTUP sprintup #define PRINTUM sprintum #define PRINTSF sprintsf +#define PRINTSYMBOL sprintsymbol +#define PRINTRANGE sprintrange #endif void PRINTEXPR(); @@ -182,6 +189,8 @@ void PRINTEOP(); void PRINTLOP(); void PRINTQOP(); void PRINTSF(); +void PRINTSYMBOL(); +void PRINTRANGE(); #ifdef FPRINT void output_init() { @@ -228,7 +237,11 @@ char *s; void myoutbrute(g) GEN g; { +# if PARI_VERSION_CODE > 131588 + brute(g, 'f', -1); +# else bruteall(g,'f',-1,1); +# endif } void sprintbf(a) @@ -292,6 +305,10 @@ Obj p; PRINTBYTEARRAY(vl,(BYTEARRAY)p); break; case O_QUOTE: PRINTQUOTE(vl,(QUOTE)p); break; + case O_SYMBOL: + PRINTSYMBOL((SYMBOL)p); break; + case O_RANGE: + PRINTRANGE(vl,(RANGE)p); break; default: break; } @@ -393,7 +410,76 @@ Num q; case MID_PRINTF_G: #endif default: - if ( real_digit ) { + if ( real_binary ) { + unsigned int *m; + unsigned int u,l,mask; + int i,expo; + + m = (unsigned int *)&BDY((Real)q); +#if defined(__i386__) || defined(MIPSEL) || defined(VISUAL) || defined(__alpha) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__x86_64) + u = m[1]; l = m[0]; +#else + u = m[0]; l = m[1]; +#endif + if (u&0x80000000) { + TAIL PRINTF(OUT,"-"); + } + u &= 0x7fffffff; + expo = ((int)(u>>20)); + u &= 0xfffff; + if ( expo == 2047 ) { + if ( u || l ) { + TAIL PRINTF(OUT,"NaN"); + } else { + TAIL PRINTF(OUT,"Inf"); + } + } else if ( expo == 0 ) { + if ( u || l ) { + TAIL PRINTF(OUT,"0b0."); + for ( i = 0, mask = 0x80000; i < 20; + i++, mask >>= 1) { + TAIL + if ( u&mask ) + PRINTF(OUT,"1"); + else + PRINTF(OUT,"0"); + } + for ( i = 0, mask = 0x80000000; i < 32; + i++, mask >>= 1) { + TAIL + if ( l&mask ) + PRINTF(OUT,"1"); + else + PRINTF(OUT,"0"); + } + TAIL PRINTF(OUT,"*2^%d",-1022); + } else { + TAIL PRINTF(OUT,"0"); + } + } else { + expo -= 1023; + TAIL PRINTF(OUT,"0b1."); + for ( i = 0, mask = 0x80000; i < 20; + i++, mask >>= 1) { + TAIL + if ( u&mask ) + PRINTF(OUT,"1"); + else + PRINTF(OUT,"0"); + } + for ( i = 0, mask = 0x80000000; i < 32; + i++, mask >>= 1) { + TAIL + if ( l&mask ) + PRINTF(OUT,"1"); + else + PRINTF(OUT,"0"); + } + if ( expo ) { + TAIL PRINTF(OUT,"*2^%d",expo); + } + } + } else if ( real_digit ) { sprintf(real_format, double_output?"%%.%df":"%%.%dg",real_digit); TAIL PRINTF(OUT,real_format,BDY((Real)q)); @@ -1098,4 +1184,18 @@ unsigned int i; } else { TAIL PRINTF(OUT,"@_%d",IFTOF(i)); } +} + +void PRINTSYMBOL(SYMBOL sym) +{ + PUTS(sym->name); +} + +void PRINTRANGE(VL vl,RANGE p) +{ + PUTS("range("); + PRINTEXPR(vl,p->start); + PUTS(","); + PRINTEXPR(vl,p->end); + PUTS(")"); }