g_ddfmt.c (187808) | g_ddfmt.c (219557) |
---|---|
1/**************************************************************** 2 3The author of this software is David M. Gay. 4 5Copyright (C) 1998 by Lucent Technologies 6All Rights Reserved 7 8Permission to use, copy, modify, and distribute this software and --- 19 unchanged lines hidden (view full) --- 28 29/* Please send bug reports to David M. Gay (dmg@acm.org). */ 30 31#include "gdtoaimp.h" 32#include <string.h> 33 34 char * 35#ifdef KR_headers | 1/**************************************************************** 2 3The author of this software is David M. Gay. 4 5Copyright (C) 1998 by Lucent Technologies 6All Rights Reserved 7 8Permission to use, copy, modify, and distribute this software and --- 19 unchanged lines hidden (view full) --- 28 29/* Please send bug reports to David M. Gay (dmg@acm.org). */ 30 31#include "gdtoaimp.h" 32#include <string.h> 33 34 char * 35#ifdef KR_headers |
36g_ddfmt(buf, dd, ndig, bufsize) char *buf; double *dd; int ndig; size_t bufsize; | 36g_ddfmt(buf, dd0, ndig, bufsize) char *buf; double *dd0; int ndig; size_t bufsize; |
37#else | 37#else |
38g_ddfmt(char *buf, double *dd, int ndig, size_t bufsize) | 38g_ddfmt(char *buf, double *dd0, int ndig, size_t bufsize) |
39#endif 40{ 41 FPI fpi; 42 char *b, *s, *se; 43 ULong *L, bits0[4], *bits, *zx; 44 int bx, by, decpt, ex, ey, i, j, mode; 45 Bigint *x, *y, *z; | 39#endif 40{ 41 FPI fpi; 42 char *b, *s, *se; 43 ULong *L, bits0[4], *bits, *zx; 44 int bx, by, decpt, ex, ey, i, j, mode; 45 Bigint *x, *y, *z; |
46 double ddx[2]; | 46 U *dd, ddx[2]; |
47#ifdef Honor_FLT_ROUNDS /*{{*/ 48 int Rounding; 49#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */ 50 Rounding = Flt_Rounds; 51#else /*}{*/ 52 Rounding = 1; 53 switch(fegetround()) { 54 case FE_TOWARDZERO: Rounding = 0; break; 55 case FE_UPWARD: Rounding = 2; break; 56 case FE_DOWNWARD: Rounding = 3; 57 } 58#endif /*}}*/ 59#else /*}{*/ 60#define Rounding FPI_Round_near 61#endif /*}}*/ 62 63 if (bufsize < 10 || bufsize < ndig + 8) 64 return 0; 65 | 47#ifdef Honor_FLT_ROUNDS /*{{*/ 48 int Rounding; 49#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */ 50 Rounding = Flt_Rounds; 51#else /*}{*/ 52 Rounding = 1; 53 switch(fegetround()) { 54 case FE_TOWARDZERO: Rounding = 0; break; 55 case FE_UPWARD: Rounding = 2; break; 56 case FE_DOWNWARD: Rounding = 3; 57 } 58#endif /*}}*/ 59#else /*}{*/ 60#define Rounding FPI_Round_near 61#endif /*}}*/ 62 63 if (bufsize < 10 || bufsize < ndig + 8) 64 return 0; 65 |
66 L = (ULong*)dd; | 66 dd = (U*)dd0; 67 L = dd->L; |
67 if ((L[_0] & 0x7ff00000L) == 0x7ff00000L) { 68 /* Infinity or NaN */ 69 if (L[_0] & 0xfffff || L[_1]) { 70 nanret: 71 return strcp(buf, "NaN"); 72 } 73 if ((L[2+_0] & 0x7ff00000) == 0x7ff00000) { 74 if (L[2+_0] & 0xfffff || L[2+_1]) --- 8 unchanged lines hidden (view full) --- 83 return strcp(b, "Infinity"); 84 } 85 if ((L[2+_0] & 0x7ff00000) == 0x7ff00000) { 86 L += 2; 87 if (L[_0] & 0xfffff || L[_1]) 88 goto nanret; 89 goto infret; 90 } | 68 if ((L[_0] & 0x7ff00000L) == 0x7ff00000L) { 69 /* Infinity or NaN */ 70 if (L[_0] & 0xfffff || L[_1]) { 71 nanret: 72 return strcp(buf, "NaN"); 73 } 74 if ((L[2+_0] & 0x7ff00000) == 0x7ff00000) { 75 if (L[2+_0] & 0xfffff || L[2+_1]) --- 8 unchanged lines hidden (view full) --- 84 return strcp(b, "Infinity"); 85 } 86 if ((L[2+_0] & 0x7ff00000) == 0x7ff00000) { 87 L += 2; 88 if (L[_0] & 0xfffff || L[_1]) 89 goto nanret; 90 goto infret; 91 } |
91 if (dd[0] + dd[1] == 0.) { | 92 if (dval(&dd[0]) + dval(&dd[1]) == 0.) { |
92 b = buf; 93#ifndef IGNORE_ZERO_SIGN 94 if (L[_0] & L[2+_0] & 0x80000000L) 95 *b++ = '-'; 96#endif 97 *b++ = '0'; 98 *b = 0; 99 return b; 100 } 101 if ((L[_0] & 0x7ff00000L) < (L[2+_0] & 0x7ff00000L)) { | 93 b = buf; 94#ifndef IGNORE_ZERO_SIGN 95 if (L[_0] & L[2+_0] & 0x80000000L) 96 *b++ = '-'; 97#endif 98 *b++ = '0'; 99 *b = 0; 100 return b; 101 } 102 if ((L[_0] & 0x7ff00000L) < (L[2+_0] & 0x7ff00000L)) { |
102 ddx[1] = dd[0]; 103 ddx[0] = dd[1]; | 103 dval(&ddx[1]) = dval(&dd[0]); 104 dval(&ddx[0]) = dval(&dd[1]); |
104 dd = ddx; | 105 dd = ddx; |
105 L = (ULong*)dd; | 106 L = dd->L; |
106 } | 107 } |
107 z = d2b(dd[0], &ex, &bx); 108 if (dd[1] == 0.) | 108 z = d2b(dval(&dd[0]), &ex, &bx); 109 if (dval(&dd[1]) == 0.) |
109 goto no_y; 110 x = z; | 110 goto no_y; 111 x = z; |
111 y = d2b(dd[1], &ey, &by); | 112 y = d2b(dval(&dd[1]), &ey, &by); |
112 if ( (i = ex - ey) !=0) { 113 if (i > 0) { 114 x = lshift(x, i); 115 ex = ey; 116 } 117 else 118 y = lshift(y, -i); 119 } --- 50 unchanged lines hidden --- | 113 if ( (i = ex - ey) !=0) { 114 if (i > 0) { 115 x = lshift(x, i); 116 ex = ey; 117 } 118 else 119 y = lshift(y, -i); 120 } --- 50 unchanged lines hidden --- |