1 /****************************************************************
2 Copyright 1990 by AT&T Bell Laboratories and Bellcore.
4 Permission to use, copy, modify, and distribute this software
5 and its documentation for any purpose and without fee is hereby
6 granted, provided that the above copyright notice appear in all
7 copies and that both that the copyright notice and this
8 permission notice and warranty disclaimer appear in supporting
9 documentation, and that the names of AT&T Bell Laboratories or
10 Bellcore or any of their entities not be used in advertising or
11 publicity pertaining to distribution of the software without
12 specific, written prior permission.
14 AT&T and Bellcore disclaim all warranties with regard to this
15 software, including all implied warranties of merchantability
16 and fitness. In no event shall AT&T or Bellcore be liable for
17 any special, indirect or consequential damages or any damages
18 whatsoever resulting from loss of use, data or profits, whether
19 in an action of contract, negligence or other tortious action,
20 arising out of or in connection with the use or performance of
22 ****************************************************************/
24 /* Put strings representing decimal floating-point numbers
25 * into canonical form: always have a decimal point or
26 * exponent field; if using an exponent field, have the
27 * number before it start with a digit and decimal point
28 * (if the number has more than one digit); only have an
29 * exponent field if it saves space.
31 * Arrange that the return value, rv, satisfies rv[0] == '-' || rv[-1] == '-' .
36 extern char *Alloc(), *mem(), *strcpy();
42 int ea, esign, et, i, k, nd = 0, sign = 0, tz;
46 static char etype[256], *db;
47 static int dblen = 64;
59 while((c = *s++) == '0');
61 { sign = 1; c = *s++; }
71 if (etype[(unsigned char)c] >= 2)
72 while(c == '0') c = *s++;
74 while(c >= '0' && c <= '9') {
89 while((c = *s++) >= '0' && c <= '9') {
106 if (et = etype[(unsigned char)c]) {
110 if(etype[(unsigned char)c] > 1) {
116 while(c >= '0' && c <= '9') {
117 ex = 10*ex + (c - '0');
124 /* debug*/ Fatal("unexpected character in cds");
132 else if (ex > 2 || ex + nd < -2) {
133 sprintf(ebuf, "%ld", ex + nd - 1);
134 k = strlen(ebuf) + nd + 3;
144 for(k = 1; k < nd; k++)
162 for(k = 0; k < nd; k++)
179 return sign ? z0 : z0+1;