source: vendor/FreeBSD-libc/current/gdtoa/test/xLtest.c

Last change on this file was 1862, checked in by bird, 21 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.5 KB
Line 
1/****************************************************************
2
3The author of this software is David M. Gay.
4
5Copyright (C) 1998-2001 by Lucent Technologies
6All Rights Reserved
7
8Permission to use, copy, modify, and distribute this software and
9its documentation for any purpose and without fee is hereby
10granted, provided that the above copyright notice appear in all
11copies and that both that the copyright notice and this
12permission notice and warranty disclaimer appear in supporting
13documentation, and that the name of Lucent or any of its entities
14not be used in advertising or publicity pertaining to
15distribution of the software without specific, written prior
16permission.
17
18LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25THIS SOFTWARE.
26
27****************************************************************/
28
29/* Please send bug reports to
30 David M. Gay
31 Bell Laboratories, Room 2C-463
32 600 Mountain Avenue
33 Murray Hill, NJ 07974-0636
34 U.S.A.
35 dmg@bell-labs.com
36 */
37
38/* Test program for g_xLfmt, strtoIxL, strtopxL, and strtorxL.
39 *
40 * Inputs (on stdin):
41 * r rounding_mode
42 * n ndig
43 * number
44 * #hex0 hex1 hex2
45 *
46 * rounding_mode values:
47 * 0 = toward zero
48 * 1 = nearest
49 * 2 = toward +Infinity
50 * 3 = toward -Infinity
51 *
52 * where number is a decimal floating-point number,
53 * hex0 is a string of <= 8 Hex digits for the most significant
54 * word of the number, hex1 is a similar string for the next
55 * word, etc., and ndig is a parameters to g_xLfmt.
56 */
57
58#include "gdtoa.h"
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62
63 extern int getround ANSI((int,char*));
64
65 static char ibuf[2048], obuf[2048];
66
67#define U (unsigned long)
68
69#undef _0
70#undef _1
71
72/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */
73
74#ifdef IEEE_MC68k
75#define _0 0
76#define _1 1
77#define _2 2
78#endif
79#ifdef IEEE_8087
80#define _0 2
81#define _1 1
82#define _2 0
83#endif
84
85 int
86main(Void)
87{
88 char *s, *se, *se1;
89 int dItry, i, ndig = 0, r = 1;
90 union { long double d; ULong bits[3]; } u, v[2];
91
92 while(s = fgets(ibuf, sizeof(ibuf), stdin)) {
93 while(*s <= ' ')
94 if (!*s++)
95 continue;
96 dItry = 0;
97 switch(*s) {
98 case 'r':
99 r = getround(r, s);
100 continue;
101 case 'n':
102 i = s[1];
103 if (i <= ' ' || i >= '0' && i <= '9') {
104 ndig = atoi(s+1);
105 continue;
106 }
107 break; /* nan? */
108 case '#':
109 sscanf(s+1, "%lx %lx %lx", &u.bits[_0],
110 &u.bits[_1], &u.bits[_2]);
111 printf("\nInput: %s", ibuf);
112 printf(" --> f = #%lx %lx %lx\n", u.bits[_0],
113 u.bits[_1], u.bits[_2]);
114 goto fmt_test;
115 }
116 dItry = 1;
117 printf("\nInput: %s", ibuf);
118 i = strtorxL(ibuf, &se, r, u.bits);
119 if (r == 1 && (i != strtopxL(ibuf, &se1, v[0].bits) || se1 != se
120 || memcmp(u.bits, v[0].bits, 12)))
121 printf("***strtoxL and strtorxL disagree!!\n:");
122 printf("\nstrtoxL consumes %d bytes and returns %d\n",
123 (int)(se-ibuf), i);
124 printf("with bits = #%lx %lx %lx\n",
125 U u.bits[_0], U u.bits[_1], U u.bits[_2]);
126 if (sizeof(long double) == 12)
127 printf("printf(\"%%.21Lg\") gives %.21Lg\n", u.d);
128 fmt_test:
129 se = g_xLfmt(obuf, u.bits, ndig, sizeof(obuf));
130 printf("g_xLfmt(%d) gives %d bytes: \"%s\"\n\n",
131 ndig, (int)(se-obuf), se ? obuf : "<null>");
132 if (!dItry)
133 continue;
134 printf("strtoIxL returns %d,",
135 strtoIxL(ibuf, &se, v[0].bits, v[1].bits));
136 printf(" consuming %d bytes.\n", (int)(se-ibuf));
137 if (!memcmp(v[0].bits, v[1].bits, 12)) {
138 if (!memcmp(u.bits, v[0].bits, 12))
139 printf("fI[0] == fI[1] == strtoxL\n");
140 else {
141 printf("fI[0] == fI[1] = #%lx %lx %lx\n",
142 U v[0].bits[_0], U v[0].bits[_1],
143 U v[0].bits[_2]);
144 if (sizeof(long double) == 12)
145 printf("= %.21Lg\n", v[0].d);
146 }
147 }
148 else {
149 printf("fI[0] = #%lx %lx %lx\n",
150 U v[0].bits[_0], U v[0].bits[_1],
151 U v[0].bits[_2]);
152 if (sizeof(long double) == 12)
153 printf("= %.21Lg\n", v[0].d);
154 printf("fI[1] = #%lx %lx %lx\n",
155 U v[1].bits[_0], U v[1].bits[_1],
156 U v[1].bits[_2]);
157 if (sizeof(long double) == 12)
158 printf("= %.21Lg\n", v[1].d);
159 if (!memcmp(v[0].bits, u.bits, 12))
160 printf("fI[0] == strtoxL\n");
161 else if (!memcmp(v[1].bits, u.bits, 12))
162 printf("fI[1] == strtoxL\n");
163 else
164 printf("**** Both differ from strtod ****\n");
165 }
166 printf("\n");
167 }
168 return 0;
169 }
Note: See TracBrowser for help on using the repository browser.