blob: 0da223796cde84666291a3d225430de93148eb17 [file] [log] [blame]
rsccfa37a72004-04-10 18:53:55 +00001.TH ATOF 3
2.SH NAME
3atof, atoi, atol, atoll, charstod, strtod, strtol, strtoll, strtoul, strtoull \- convert text to numbers
4.SH SYNOPSIS
5.B #include <u.h>
6.br
7.B #include <libc.h>
8.PP
9.nf
10.ta \w'\fLdouble 'u
11.B
12double atof(char *nptr)
13.PP
14.B
15int atoi(char *nptr)
16.PP
17.B
18long atol(char *nptr)
19.PP
20.B
21vlong atoll(char *nptr)
22.PP
23.B
24double charstod(int (*f)(void *), void *a)
25.PP
26.B
27double strtod(char *nptr, char **rptr)
28.PP
29.B
30long strtol(char *nptr, char **rptr, int base)
31.PP
32.B
33vlong strtoll(char *nptr, char **rptr, int base)
34.PP
35.B
36ulong strtoul(char *nptr, char **rptr, int base)
37.PP
38.B
39vlong strtoull(char *nptr, char **rptr, int base)
40.fi
41.SH DESCRIPTION
42.IR Atof ,
43.IR atoi ,
44.IR atol ,
45and
46.I atoll
47convert a string pointed to by
48.I nptr
49to floating, integer, long integer, and long long integer
50.RB ( vlong )
51representation respectively.
52The first unrecognized character ends the string.
53Leading C escapes are understood, as in
54.I strtol
55with
56.I base
57zero (described below).
58.PP
59.I Atof
60recognizes an optional string of tabs and spaces,
61then an optional sign, then
62a string of digits optionally containing a decimal
63point, then an optional
64.L e
65or
66.L E
67followed
68by an optionally signed integer.
69.PP
70.I Atoi
71and
72.I atol
73recognize an optional string of tabs and spaces,
74then an optional sign, then a string of
75decimal digits.
76.PP
77.IR Strtod ,
78.IR strtol ,
79.IR strtoll ,
80.IR strtoul ,
81and
82.I strtoull
83behave similarly to
84.I atof
85and
86.I atol
87and, if
88.I rptr
89is not zero, set
90.I *rptr
91to point to the input character
92immediately after the string converted.
93.PP
94.IR Strtol ,
95.IR strtoll ,
96.IR strtoul ,
97and
98.IR strtoull
99interpret the digit string in the specified
100.IR base ,
101from 2 to 36,
102each digit being less than the base.
103Digits with value over 9 are represented by letters,
104a-z or A-Z.
105If
106.I base
107is 0, the input is interpreted as an integral constant in
108the style of C (with no suffixed type indicators):
109numbers are octal if they begin with
110.LR 0 ,
111hexadecimal if they begin with
112.L 0x
113or
114.LR 0X ,
115otherwise decimal.
116.PP
117.I Charstod
118interprets floating point numbers in the manner of
119.IR atof ,
120but gets successive characters by calling
121.BR (*\fIf\fP)(a) .
122The last call to
123.I f
124terminates the scan, so it must have returned a character that
125is not a legal continuation of a number.
126Therefore, it may be necessary to back up the input stream one character
127after calling
128.IR charstod .
129.SH SOURCE
rscc3674de2005-01-11 17:37:33 +0000130.B \*9/src/lib9
rsccfa37a72004-04-10 18:53:55 +0000131.SH SEE ALSO
rscbf8a59f2004-04-11 03:42:27 +0000132.IR fscanf (3)
rsccfa37a72004-04-10 18:53:55 +0000133.SH DIAGNOSTICS
134Zero is returned if the beginning of the input string is not
135interpretable as a number; even in this case,
136.I rptr
137will be updated.
138.br
139These routines set
140.IR errstr .
141.SH BUGS
142.I Atoi
143and
144.I atol
145accept octal and hexadecimal numbers in the style of C,
146contrary to the ANSI specification.
rscc8b63422005-01-13 04:49:19 +0000147.PP
148.IR Atof ,
149.IR strtod ,
150.IR strtol ,
151.IR strtoul ,
152.IR strtoll ,
153and
154.IR strtoull
155are not provided:
156they are expected to be provided by the underlying system.
157.PP
158Because they are implemented in the fmt library,
159.I charstod
160and
161.I strtod
162are preprocessor macros defined as
163.I fmtcharstod
164and
165.IR fmtstrtod .
166.PP
167To avoid name conflicts with the underlying system,
168.IR atoi ,
169.IR atol ,
170and
171.I atoll
172are preprocessor macros defined as
173.IR p9atoi ,
174.IR p9atol ,
175and
176.IR p9atoll ;
177see
178.IR intro (3).