| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
#include "gdtoaimp.h" |
| 53 |
#include <stdio.h> |
| 54 |
#include <stdlib.h> |
| 55 |
|
| 56 |
extern int getround ANSI((int,char*)); |
| 57 |
|
| 58 |
static char ibuf[2048], obuf[2048], obuf1[2048]; |
| 59 |
|
| 60 |
#define UL (unsigned long) |
| 61 |
|
| 62 |
int |
| 63 |
main(Void) |
| 64 |
{ |
| 65 |
U fI[2], u; |
| 66 |
char *s, *se, *se1; |
| 67 |
double f1; |
| 68 |
int i, i1, ndig = 0, nik, nike, r = 1; |
| 69 |
long LL[2]; |
| 70 |
|
| 71 |
while( (s = fgets(ibuf, sizeof(ibuf), stdin)) !=0) { |
| 72 |
while(*s <= ' ') |
| 73 |
if (!*s++) |
| 74 |
continue; |
| 75 |
switch(*s) { |
| 76 |
case 'r': |
| 77 |
r = getround(r, s); |
| 78 |
continue; |
| 79 |
case 'n': |
| 80 |
i = s[1]; |
| 81 |
if (i <= ' ' || (i >= '0' && i <= '9')) { |
| 82 |
ndig = atoi(s+1); |
| 83 |
continue; |
| 84 |
} |
| 85 |
break; |
| 86 |
case '#': |
| 87 |
LL[0] = u.L[_0]; |
| 88 |
LL[1] = u.L[_1]; |
| 89 |
sscanf(s+1, "%lx %lx", &LL[0], &LL[1]); |
| 90 |
u.L[_0] = LL[0]; |
| 91 |
u.L[_1] = LL[1]; |
| 92 |
printf("\nInput: %s", ibuf); |
| 93 |
printf("--> f = #%lx %lx\n", (long)u.L[_0], (long)u.L[_1]); |
| 94 |
i = 0; |
| 95 |
goto fmt_test; |
| 96 |
} |
| 97 |
printf("\nInput: %s", ibuf); |
| 98 |
i = strtord(ibuf, &se, r, &u.d); |
| 99 |
if (r == 1) { |
| 100 |
if ((u.d != strtod(ibuf, &se1) || se1 != se)) |
| 101 |
printf("***strtod and strtord disagree!!\n"); |
| 102 |
i1 = strtopd(ibuf, &se, &f1); |
| 103 |
if (i != i1 || u.d != f1 || se != se1) |
| 104 |
printf("***strtord and strtopd disagree!!\n"); |
| 105 |
} |
| 106 |
printf("strtord consumes %d bytes and returns %d with f = %.17g = #%lx %lx\n", |
| 107 |
(int)(se-ibuf), i, u.d, UL u.L[_0], UL u.L[_1]); |
| 108 |
fmt_test: |
| 109 |
se = g_dfmt(obuf, &u.d, ndig, sizeof(obuf)); |
| 110 |
printf("g_dfmt(%d) gives %d bytes: \"%s\"\n\n", |
| 111 |
ndig, (int)(se-obuf), se ? obuf : "<null>"); |
| 112 |
se1 = g_dfmt_p(obuf1, &u.d, ndig, sizeof(obuf1), 0); |
| 113 |
if (se1 - obuf1 != se - obuf || strcmp(obuf, obuf1)) |
| 114 |
printf("Botch: g_dfmt_p gives \"%s\" rather than \"%s\"\n", |
| 115 |
obuf1, obuf); |
| 116 |
if (*s == '#') |
| 117 |
continue; |
| 118 |
printf("strtoId returns %d,", strtoId(ibuf, &se, &fI[0].d, &fI[1].d)); |
| 119 |
printf(" consuming %d bytes.\n", (int)(se-ibuf)); |
| 120 |
if (fI[0].d == fI[1].d) { |
| 121 |
if (fI[0].d == u.d) |
| 122 |
printf("fI[0] == fI[1] == strtod\n"); |
| 123 |
else |
| 124 |
printf("fI[0] == fI[1] = #%lx %lx = %.17g\n", |
| 125 |
UL fI[0].L[_0], UL fI[0].L[_1], fI[0].d); |
| 126 |
} |
| 127 |
else { |
| 128 |
printf("fI[0] = #%lx %lx = %.17g\n", |
| 129 |
UL fI[0].L[_0], UL fI[0].L[_1], fI[0].d); |
| 130 |
printf("fI[1] = #%lx %lx = %.17g\n", |
| 131 |
UL fI[1].L[_0], UL fI[1].L[_1], fI[1].d); |
| 132 |
if (fI[0].d == u.d) |
| 133 |
printf("fI[0] == strtod\n"); |
| 134 |
else if (fI[1].d == u.d) |
| 135 |
printf("fI[1] == strtod\n"); |
| 136 |
else |
| 137 |
printf("**** Both differ from strtod ****\n"); |
| 138 |
} |
| 139 |
printf("\n"); |
| 140 |
switch(i & STRTOG_Retmask) { |
| 141 |
case STRTOG_Infinite: |
| 142 |
for(nik = 0; nik < 6; ++nik) { |
| 143 |
se1 = g_dfmt_p(obuf1, &u.d, ndig, sizeof(obuf1), nik); |
| 144 |
printf("g_dfmt_p(...,%d): \"%s\"\n", nik, obuf1); |
| 145 |
} |
| 146 |
break; |
| 147 |
case STRTOG_NaN: |
| 148 |
case STRTOG_NaNbits: |
| 149 |
for(i = 0; i < 3; ++i) |
| 150 |
for(nik = 6*i, nike = nik + 3; nik < nike; ++nik) { |
| 151 |
se1 = g_dfmt_p(obuf1, &u.d, ndig, sizeof(obuf1), nik); |
| 152 |
printf("g_dfmt_p(...,%d): \"%s\"\n", nik, obuf1); |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
return 0; |
| 157 |
} |