1 cfa37a7b 2004-04-10 devnull .TH ATOF 3
3 cfa37a7b 2004-04-10 devnull atof, atoi, atol, atoll, charstod, strtod, strtol, strtoll, strtoul, strtoull \- convert text to numbers
4 cfa37a7b 2004-04-10 devnull .SH SYNOPSIS
5 cfa37a7b 2004-04-10 devnull .B #include <u.h>
7 cfa37a7b 2004-04-10 devnull .B #include <libc.h>
10 cfa37a7b 2004-04-10 devnull .ta \w'\fLdouble 'u
12 cfa37a7b 2004-04-10 devnull double atof(char *nptr)
15 cfa37a7b 2004-04-10 devnull int atoi(char *nptr)
18 cfa37a7b 2004-04-10 devnull long atol(char *nptr)
21 cfa37a7b 2004-04-10 devnull vlong atoll(char *nptr)
24 cfa37a7b 2004-04-10 devnull double charstod(int (*f)(void *), void *a)
27 cfa37a7b 2004-04-10 devnull double strtod(char *nptr, char **rptr)
30 cfa37a7b 2004-04-10 devnull long strtol(char *nptr, char **rptr, int base)
33 cfa37a7b 2004-04-10 devnull vlong strtoll(char *nptr, char **rptr, int base)
36 cfa37a7b 2004-04-10 devnull ulong strtoul(char *nptr, char **rptr, int base)
39 cfa37a7b 2004-04-10 devnull vlong strtoull(char *nptr, char **rptr, int base)
41 cfa37a7b 2004-04-10 devnull .SH DESCRIPTION
42 cfa37a7b 2004-04-10 devnull .IR Atof ,
43 cfa37a7b 2004-04-10 devnull .IR atoi ,
44 cfa37a7b 2004-04-10 devnull .IR atol ,
47 cfa37a7b 2004-04-10 devnull convert a string pointed to by
49 cfa37a7b 2004-04-10 devnull to floating, integer, long integer, and long long integer
50 cfa37a7b 2004-04-10 devnull .RB ( vlong )
51 cfa37a7b 2004-04-10 devnull representation respectively.
52 cfa37a7b 2004-04-10 devnull The first unrecognized character ends the string.
53 cfa37a7b 2004-04-10 devnull Leading C escapes are understood, as in
54 cfa37a7b 2004-04-10 devnull .I strtol
57 cfa37a7b 2004-04-10 devnull zero (described below).
60 cfa37a7b 2004-04-10 devnull recognizes an optional string of tabs and spaces,
61 cfa37a7b 2004-04-10 devnull then an optional sign, then
62 cfa37a7b 2004-04-10 devnull a string of digits optionally containing a decimal
63 cfa37a7b 2004-04-10 devnull point, then an optional
68 cfa37a7b 2004-04-10 devnull by an optionally signed integer.
73 cfa37a7b 2004-04-10 devnull recognize an optional string of tabs and spaces,
74 cfa37a7b 2004-04-10 devnull then an optional sign, then a string of
75 cfa37a7b 2004-04-10 devnull decimal digits.
77 cfa37a7b 2004-04-10 devnull .IR Strtod ,
78 cfa37a7b 2004-04-10 devnull .IR strtol ,
79 cfa37a7b 2004-04-10 devnull .IR strtoll ,
80 cfa37a7b 2004-04-10 devnull .IR strtoul ,
82 cfa37a7b 2004-04-10 devnull .I strtoull
83 cfa37a7b 2004-04-10 devnull behave similarly to
89 cfa37a7b 2004-04-10 devnull is not zero, set
91 cfa37a7b 2004-04-10 devnull to point to the input character
92 cfa37a7b 2004-04-10 devnull immediately after the string converted.
94 cfa37a7b 2004-04-10 devnull .IR Strtol ,
95 cfa37a7b 2004-04-10 devnull .IR strtoll ,
96 cfa37a7b 2004-04-10 devnull .IR strtoul ,
98 cfa37a7b 2004-04-10 devnull .IR strtoull
99 cfa37a7b 2004-04-10 devnull interpret the digit string in the specified
100 cfa37a7b 2004-04-10 devnull .IR base ,
101 cfa37a7b 2004-04-10 devnull from 2 to 36,
102 cfa37a7b 2004-04-10 devnull each digit being less than the base.
103 cfa37a7b 2004-04-10 devnull Digits with value over 9 are represented by letters,
104 cfa37a7b 2004-04-10 devnull a-z or A-Z.
107 cfa37a7b 2004-04-10 devnull is 0, the input is interpreted as an integral constant in
108 cfa37a7b 2004-04-10 devnull the style of C (with no suffixed type indicators):
109 cfa37a7b 2004-04-10 devnull numbers are octal if they begin with
111 cfa37a7b 2004-04-10 devnull hexadecimal if they begin with
114 cfa37a7b 2004-04-10 devnull .LR 0X ,
115 cfa37a7b 2004-04-10 devnull otherwise decimal.
117 cfa37a7b 2004-04-10 devnull .I Charstod
118 cfa37a7b 2004-04-10 devnull interprets floating point numbers in the manner of
119 cfa37a7b 2004-04-10 devnull .IR atof ,
120 cfa37a7b 2004-04-10 devnull but gets successive characters by calling
121 cfa37a7b 2004-04-10 devnull .BR (*\fIf\fP)(a) .
122 cfa37a7b 2004-04-10 devnull The last call to
124 cfa37a7b 2004-04-10 devnull terminates the scan, so it must have returned a character that
125 cfa37a7b 2004-04-10 devnull is not a legal continuation of a number.
126 cfa37a7b 2004-04-10 devnull Therefore, it may be necessary to back up the input stream one character
127 cfa37a7b 2004-04-10 devnull after calling
128 cfa37a7b 2004-04-10 devnull .IR charstod .
129 cfa37a7b 2004-04-10 devnull .SH SOURCE
130 c3674de4 2005-01-11 devnull .B \*9/src/lib9
131 cfa37a7b 2004-04-10 devnull .SH SEE ALSO
132 bf8a59fa 2004-04-11 devnull .IR fscanf (3)
133 cfa37a7b 2004-04-10 devnull .SH DIAGNOSTICS
134 cfa37a7b 2004-04-10 devnull Zero is returned if the beginning of the input string is not
135 cfa37a7b 2004-04-10 devnull interpretable as a number; even in this case,
137 cfa37a7b 2004-04-10 devnull will be updated.
139 cfa37a7b 2004-04-10 devnull These routines set
140 cfa37a7b 2004-04-10 devnull .IR errstr .
141 cfa37a7b 2004-04-10 devnull .SH BUGS
145 cfa37a7b 2004-04-10 devnull accept octal and hexadecimal numbers in the style of C,
146 cfa37a7b 2004-04-10 devnull contrary to the ANSI specification.
148 c8b6342d 2005-01-13 devnull .IR Atof ,
149 c8b6342d 2005-01-13 devnull .IR strtod ,
150 c8b6342d 2005-01-13 devnull .IR strtol ,
151 c8b6342d 2005-01-13 devnull .IR strtoul ,
152 c8b6342d 2005-01-13 devnull .IR strtoll ,
154 c8b6342d 2005-01-13 devnull .IR strtoull
155 c8b6342d 2005-01-13 devnull are not provided:
156 c8b6342d 2005-01-13 devnull they are expected to be provided by the underlying system.
158 c8b6342d 2005-01-13 devnull Because they are implemented in the fmt library,
159 c8b6342d 2005-01-13 devnull .I charstod
161 c8b6342d 2005-01-13 devnull .I strtod
162 c8b6342d 2005-01-13 devnull are preprocessor macros defined as
163 c8b6342d 2005-01-13 devnull .I fmtcharstod
165 c8b6342d 2005-01-13 devnull .IR fmtstrtod .
167 c8b6342d 2005-01-13 devnull To avoid name conflicts with the underlying system,
168 c8b6342d 2005-01-13 devnull .IR atoi ,
169 c8b6342d 2005-01-13 devnull .IR atol ,
171 c8b6342d 2005-01-13 devnull .I atoll
172 c8b6342d 2005-01-13 devnull are preprocessor macros defined as
173 c8b6342d 2005-01-13 devnull .IR p9atoi ,
174 c8b6342d 2005-01-13 devnull .IR p9atol ,
176 c8b6342d 2005-01-13 devnull .IR p9atoll ;
178 c8b6342d 2005-01-13 devnull .IR intro (3).