//摘自 od 的反汇编引擎中的 asmserv.c 文件
代码:
// Decodes and prints 80-bit long double ext into string s (at least 32 bytes // long). Procedure correctly displays all, even invalid, numbers without // arithmetical exceptions. Returns resulting length of the string. int Printfloat10(char *s,long double ext) { int k; char *e=(char *)&ext; if (*(ulong *)e==0 && *(ushort *)(e+4)==0 && *(ulong *)(e+6)==0x7FFF8000L) { k=sprintf(s,"+INF 7FFF 80000000 00000000"); } else if (*(ulong *)e==0 && *(ushort *)(e+4)==0 && *(ulong *)(e+6)==0xFFFF8000L) { k=sprintf(s,"-INF FFFF 80000000 00000000"); } else if ((*(ulong *)(e+6) & 0x7FFF8000L)==0x7FFF8000L) { k=sprintf(s,"%cNAN %04X %08lX %08lX",(e[9] & 0x80)==0?'+':'-', (int)(*(ushort *)(e+8)),*(ulong *)(e+4),*(ulong *)e); } else if ((*(ulong *)(e+6) & 0x7FFF0000L)==0x7FFF0000L) { k=sprintf(s,"%c??? %04X %08lX %08lX",(e[9] & 0x80)==0?'+':'-',(int)(*(ushort *)(e+8)),*(ulong *)(e+4),*(ulong *)e); } else if ((*(ulong *)(e+6) & 0x7FFF0000L)!=0 && (*(ulong *)(e+6) & 0x00008000)==0) { k=sprintf(s,"%cUNORM %04X %08lX %08lX",(e[9] & 0x80)==0?'+':'-',(int)(*(ushort *)(e+8)),*(ulong *)(e+4),*(ulong *)e); } else if (*(ulong *)e==0 && *(ushort *)(e+4)==0 && *(ulong *)(e+6)==0x80000000L) { k=sprintf(s,"-0.0"); // Negative floating 0.0 } else if (ext==0.0) { k=sprintf(s,"0.0"); // Print 0 with decimal point } else if ((ext>=-1.e10 && ext<-1.0) || (ext>1.0 && ext<=1.e10)) { k=sprintf(s,"%#.20Lg",ext);//出错就在这里 } else if ((ext>=-1.0 && ext<=-1.e-5) || (ext>=1.e-5 && ext<=1.0)) { k=sprintf(s,"%#.19Lf",ext); } else { k=sprintf(s,"%#.19Le",ext); //出错就在这里 } return k; };