=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/io/pexpr.c,v retrieving revision 1.24 retrieving revision 1.28 diff -u -p -r1.24 -r1.28 --- OpenXM_contrib2/asir2000/io/pexpr.c 2003/06/09 16:18:10 1.24 +++ OpenXM_contrib2/asir2000/io/pexpr.c 2004/02/04 07:42:07 1.28 @@ -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.23 2003/06/07 16:40:25 saito Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/io/pexpr.c,v 1.27 2003/12/25 02:40:24 noro Exp $ */ #include "ca.h" #include "al.h" @@ -52,6 +52,10 @@ #include "comp.h" #include "base.h" +#if defined(PARI) +#include "genpari.h" +#endif + #ifndef FPRINT #define FPRINT #endif @@ -67,6 +71,7 @@ int hex_output; int fortran_output; int double_output; int real_digit; +int real_binary; int print_quote; #define TAIL @@ -102,6 +107,7 @@ int print_quote; #define PRINTUP printup #define PRINTUM printum #define PRINTSF printsf +#define PRINTSYMBOL printsymbol #endif #ifdef SPRINT @@ -112,6 +118,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; @@ -148,6 +155,7 @@ extern int print_quote; #define PRINTUP sprintup #define PRINTUM sprintum #define PRINTSF sprintsf +#define PRINTSYMBOL sprintsymbol #endif void PRINTEXPR(); @@ -179,6 +187,7 @@ void PRINTEOP(); void PRINTLOP(); void PRINTQOP(); void PRINTSF(); +void PRINTSYMBOL(); #ifdef FPRINT void output_init() { @@ -209,8 +218,6 @@ P p; void printbf(a) BF a; { - void sor(); - sor(a->body,double_output ? 'f' : 'g',-1,0); } #endif @@ -224,8 +231,6 @@ char *s; } #if defined(PARI) -#include "genpari.h" - void myoutbrute(g) GEN g; { @@ -236,7 +241,6 @@ void sprintbf(a) BF a; { char *str; - char *GENtostr(); char *GENtostr0(); if ( double_output ) { @@ -294,6 +298,8 @@ Obj p; PRINTBYTEARRAY(vl,(BYTEARRAY)p); break; case O_QUOTE: PRINTQUOTE(vl,(QUOTE)p); break; + case O_SYMBOL: + PRINTSYMBOL((Symbol)p); break; default: break; } @@ -395,7 +401,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)); @@ -1100,4 +1175,9 @@ unsigned int i; } else { TAIL PRINTF(OUT,"@_%d",IFTOF(i)); } +} + +void PRINTSYMBOL(Symbol p) +{ + PUTS(p->name); }