1 /****************************************************************
3 The author of this software is David M. Gay.
5 Copyright (C) 1998-2001 by Lucent Technologies
8 Permission to use, copy, modify, and distribute this software and
9 its documentation for any purpose and without fee is hereby
10 granted, provided that the above copyright notice appear in all
11 copies and that both that the copyright notice and this
12 permission notice and warranty disclaimer appear in supporting
13 documentation, and that the name of Lucent or any of its entities
14 not be used in advertising or publicity pertaining to
15 distribution of the software without specific, written prior
18 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
27 ****************************************************************/
29 /* Please send bug reports to
31 Bell Laboratories, Room 2C-463
33 Murray Hill, NJ 07974-0636
38 /* Test program for g_dfmt, strtoId, strtod, strtopd, and strtord.
46 * rounding_mode values:
49 * 2 = toward +Infinity
50 * 3 = toward -Infinity
52 * where number is a decimal floating-point number,
53 * hex0 is a string of Hex <= 8 digits for the most significant
54 * word of the number, hex1 is a similar string for the other
55 * (least significant) word, and ndig is a parameters to g_dfmt.
62 extern int getround ANSI((int,char*));
64 static char ibuf[2048], obuf[1024];
66 #define U (unsigned long)
74 int i, i1, ndig = 0, r = 1;
78 while( (s = fgets(ibuf, sizeof(ibuf), stdin)) !=0) {
88 if (i <= ' ' || i >= '0' && i <= '9') {
96 sscanf(s+1, "%lx %lx", &LL[0], &LL[1]);
99 printf("\nInput: %s", ibuf);
100 printf("--> f = #%lx %lx\n", (long)L[_0], (long)L[_1]);
103 printf("\nInput: %s", ibuf);
104 i = strtord(ibuf, &se, r, &f);
106 if ((f != strtod(ibuf, &se1) || se1 != se))
107 printf("***strtod and strtord disagree!!\n");
108 i1 = strtopd(ibuf, &se, &f1);
109 if (i != i1 || f != f1 || se != se1)
110 printf("***strtord and strtopd disagree!!\n");
112 printf("strtod consumes %d bytes and returns %d with f = %.17g = #%lx %lx\n",
113 (int)(se-ibuf), i, f, U L[_0], U L[_1]);
115 se = g_dfmt(obuf, &f, ndig, sizeof(obuf));
116 printf("g_dfmt(%d) gives %d bytes: \"%s\"\n\n",
117 ndig, (int)(se-obuf), se ? obuf : "<null>");
120 printf("strtoId returns %d,", strtoId(ibuf, &se, fI, &fI[1]));
121 printf(" consuming %d bytes.\n", (int)(se-ibuf));
122 if (fI[0] == fI[1]) {
124 printf("fI[0] == fI[1] == strtod\n");
126 printf("fI[0] == fI[1] = #%lx %lx = %.17g\n",
127 U ((ULong*)fI)[_0], U ((ULong*)fI)[_1],
131 printf("fI[0] = #%lx %lx = %.17g\n",
132 U ((ULong*)fI)[_0], U ((ULong*)fI)[_1], fI[0]);
133 printf("fI[1] = #%lx %lx = %.17g\n",
134 U ((ULong*)&fI[1])[_0], U ((ULong*)&fI[1])[_1],
137 printf("fI[0] == strtod\n");
139 printf("fI[1] == strtod\n");
141 printf("**** Both differ from strtod ****\n");