1: /*
2: * Copyright (c) 1987 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #if defined(LIBC_SCCS) && !defined(lint)
8: static char sccsid[] = "@(#)atof.c 2.2 (Berkeley) 1/22/87";
9: #endif LIBC_SCCS and not lint
10:
11: /*
12: * C library - ascii to floating
13: */
14:
15: #include <math.h>
16: #include <ctype.h>
17:
18: double
19: atof(p)
20: register char *p;
21: {
22: register c;
23: double fl, flexp, exp5;
24: double big = 72057594037927936.; /*2^56*/
25: double ldexp();
26: int nd;
27: register eexp, exp, neg, negexp, bexp;
28:
29: neg = 1;
30: while((c = *p++) == ' ')
31: ;
32: if (c == '-')
33: neg = -1;
34: else if (c=='+')
35: ;
36: else
37: --p;
38:
39: exp = 0;
40: fl = 0;
41: nd = 0;
42: while ((c = *p++), isdigit(c)) {
43: if (fl<big)
44: fl = 10*fl + (c-'0');
45: else
46: exp++;
47: nd++;
48: }
49:
50: if (c == '.') {
51: while ((c = *p++), isdigit(c)) {
52: if (fl<big) {
53: fl = 10*fl + (c-'0');
54: exp--;
55: }
56: nd++;
57: }
58: }
59:
60: negexp = 1;
61: eexp = 0;
62: if ((c == 'E') || (c == 'e')) {
63: if ((c= *p++) == '+')
64: ;
65: else if (c=='-')
66: negexp = -1;
67: else
68: --p;
69:
70: while ((c = *p++), isdigit(c)) {
71: eexp = 10*eexp+(c-'0');
72: }
73: if (negexp<0)
74: eexp = -eexp;
75: exp = exp + eexp;
76: }
77:
78: negexp = 1;
79: if (exp<0) {
80: negexp = -1;
81: exp = -exp;
82: }
83:
84:
85: if((nd+exp*negexp) < -LOGHUGE){
86: fl = 0;
87: exp = 0;
88: }
89: flexp = 1;
90: exp5 = 5;
91: bexp = exp;
92: for (;;) {
93: if (exp&01)
94: flexp *= exp5;
95: exp >>= 1;
96: if (exp==0)
97: break;
98: exp5 *= exp5;
99: }
100: if (negexp<0)
101: fl /= flexp;
102: else
103: fl *= flexp;
104: fl = ldexp(fl, negexp*bexp);
105: if (neg<0)
106: fl = -fl;
107: return(fl);
108: }
Defined functions
atof
defined in line
18; used 88 times
- in /usr/include/math.h line
10
- in /usr/include/stdlib.h line
72
- in /usr/src/bin/awk/awk.def line
57
- in /usr/src/bin/awk/lib.c line
164
- in /usr/src/bin/awk/run.c line
644,
661
- in /usr/src/bin/awk/tran.c line
176
- in /usr/src/bin/csh/sh.func.c line
940-943(2),
956
- in /usr/src/bin/tcsh/sh.func.c line
1381-1384(2),
1414-1416(2)
- in /usr/src/include/math.h line
10
- in /usr/src/lib/ccom/TEST/tpr.c line
19
- in /usr/src/lib/ccom/c11.c line
834,
1047
- in /usr/src/lib/libc/stdio/doscan.c line
106,
188-192(2)
- in /usr/src/lib/mip/pass1.h line
198
- in /usr/src/lib/pcc/local.c line
403-406(2)
- in /usr/src/new/PORT/perl.1.0.0/perl.h line
182
- in /usr/src/new/PORT/perl.1.0.0/str.c line
90,
446,
483
- in /usr/src/new/PORT/perl.1.0.0/x2p/str.c line
54,
362,
399
- in /usr/src/new/PORT/perl.1.0.10/perl.h line
211
- in /usr/src/new/PORT/perl.1.0.10/str.c line
93,
449,
486
- in /usr/src/new/PORT/perl.1.0.10/x2p/str.c line
54,
362,
399
- in /usr/src/new/PORT/perl.1.0.16/perl.h line
211
- in /usr/src/new/PORT/perl.1.0.16/str.c line
93,
449,
486
- in /usr/src/new/PORT/perl.1.0.16/x2p/str.c line
54,
362,
399
- in /usr/src/ucb/PORT/pascal/pdx/defs.h line
47
- in /usr/src/ucb/PORT/pascal/pdx/library.c line
39
- in /usr/src/ucb/PORT/pascal/src/0.h line
703,
711
- in /usr/src/ucb/PORT/pascal/src/const.c line
194,
210
- in /usr/src/ucb/PORT/pascal/src/rval.c line
1001,
1038-1041(2),
1172,
1188
- in /usr/src/ucb/PORT/pascal/src/stkrval.c line
340,
370-373(2)
- in /usr/src/ucb/indent/args.c line
192,
212
- in /usr/src/ucb/pascal/pi/0.h line
608-613(2)
- in /usr/src/ucb/pascal/pi/const.c line
136,
152
- in /usr/src/ucb/pascal/pi/rval.c line
506,
524
- in /usr/src/usr.bin/f77/misc.c line
239,
250
- in /usr/src/usr.bin/graph/graph.c line
47,
236
- in /usr/src/usr.bin/lint/lint.c line
947
- in /usr/src/usr.bin/printf/printf.c line
52,
391
- in /usr/src/usr.bin/spline.c line
232,
263,
329-334(2)
- in /usr/src/usr.bin/uucp/uuq.c line
99
- in /usr/src/usr.sbin/lpr/filters/rvsort.c line
19,
84
- in /usr/src/usr.sbin/lpr/filters/vsort.c line
19,
105
- in /usr/src/usr.sbin/lpr/pac.c line
64,
89,
176
- in /usr/src/usr.sbin/ntp/ntpd.c line
197,
782
Defined variables
sccsid
defined in line
8;
never used