]>
Commit | Line | Data |
---|---|---|
1 | .\" Copyright (c) 1990, 1991, 1993 | |
2 | .\" The Regents of the University of California. All rights reserved. | |
3 | .\" | |
4 | .\" This code is derived from software contributed to Berkeley by | |
5 | .\" the American National Standards Committee X3, on Information | |
6 | .\" Processing Systems. | |
7 | .\" | |
8 | .\" Redistribution and use in source and binary forms, with or without | |
9 | .\" modification, are permitted provided that the following conditions | |
10 | .\" are met: | |
11 | .\" 1. Redistributions of source code must retain the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer. | |
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
14 | .\" notice, this list of conditions and the following disclaimer in the | |
15 | .\" documentation and/or other materials provided with the distribution. | |
16 | .\" 3. All advertising materials mentioning features or use of this software | |
17 | .\" must display the following acknowledgement: | |
18 | .\" This product includes software developed by the University of | |
19 | .\" California, Berkeley and its contributors. | |
20 | .\" 4. Neither the name of the University nor the names of its contributors | |
21 | .\" may be used to endorse or promote products derived from this software | |
22 | .\" without specific prior written permission. | |
23 | .\" | |
24 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
25 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | .\" SUCH DAMAGE. | |
35 | .\" | |
36 | .\" @(#)strtod.3 8.1 (Berkeley) 6/4/93 | |
37 | .\" $FreeBSD: src/lib/libc/stdlib/strtod.3,v 1.19 2003/05/22 13:02:28 ru Exp $ | |
38 | .\" | |
39 | .Dd March 2, 2003 | |
40 | .Dt STRTOD 3 | |
41 | .Os | |
42 | .Sh NAME | |
43 | .Nm strtod , strtof , strtold | |
44 | .Nd convert | |
45 | .Tn ASCII | |
46 | string to floating point | |
47 | .Sh LIBRARY | |
48 | .Lb libc | |
49 | .Sh SYNOPSIS | |
50 | .In stdlib.h | |
51 | .Ft double | |
52 | .Fo strtod | |
53 | .Fa "const char *restrict nptr" | |
54 | .Fa "char **restrict endptr" | |
55 | .Fc | |
56 | .Ft float | |
57 | .Fo strtof | |
58 | .Fa "const char *restrict nptr" | |
59 | .Fa "char **restrict endptr" | |
60 | .Fc | |
61 | .Ft "long double" | |
62 | .Fo strtold | |
63 | .Fa "const char *restrict nptr" | |
64 | .Fa "char **restrict endptr" | |
65 | .Fc | |
66 | .Sh DESCRIPTION | |
67 | These conversion | |
68 | functions convert the initial portion of the string | |
69 | pointed to by | |
70 | .Fa nptr | |
71 | to | |
72 | .Vt double , | |
73 | .Vt float , | |
74 | and | |
75 | .Vt "long double" | |
76 | representation, respectively. | |
77 | .Pp | |
78 | The expected form of the string | |
79 | is an optional plus (``+'') or minus (``\-'') sign, | |
80 | followed by either: | |
81 | .Bl -bullet | |
82 | .It | |
83 | a decimal significand, consisting of a sequence of decimal digits | |
84 | (optionally containing a decimal-point character) or | |
85 | .It | |
86 | a hexadecimal significand, consisting of a ``0X'' or ``0x'' followed | |
87 | by a sequence of hexadecimal digits | |
88 | (optionally containing a decimal-point character). | |
89 | .El | |
90 | .Pp | |
91 | In both cases, the significand may be optionally followed by an | |
92 | exponent. | |
93 | An exponent consists of an ``E'' or ``e'' (for decimal | |
94 | constants) or a ``P'' or ``p'' (for hexadecimal constants), | |
95 | followed by an optional plus or minus sign, followed by a | |
96 | sequence of decimal digits. | |
97 | For decimal constants, the exponent indicates the power of 10 by | |
98 | which the significand should be scaled. | |
99 | For hexadecimal constants, the scaling is instead done by powers | |
100 | of 2. | |
101 | .Pp | |
102 | Alternatively, if the portion of the string following the optional | |
103 | plus or minus sign begins with ``INFINITY'' or ``NAN'', ignoring | |
104 | case, it is interpreted as an infinity or a quiet NaN, respectively. | |
105 | .Pp | |
106 | In any of the above cases, leading white-space characters in the | |
107 | string (as defined by the | |
108 | .Xr isspace 3 | |
109 | function) are skipped. | |
110 | The decimal point | |
111 | character is defined in the program's locale (category | |
112 | .Dv LC_NUMERIC ) . | |
113 | .Pp | |
114 | Extended locale versions of these functions are documented in | |
115 | .Xr strtod_l 3 . | |
116 | See | |
117 | .Xr xlocale 3 | |
118 | for more information. | |
119 | .Sh RETURN VALUES | |
120 | The | |
121 | .Fn strtod , | |
122 | .Fn strtof , | |
123 | and | |
124 | .Fn strtold | |
125 | functions return the converted value, if any. | |
126 | .Pp | |
127 | If | |
128 | .Fa endptr | |
129 | is not | |
130 | .Dv NULL , | |
131 | a pointer to the character after the last character used | |
132 | in the conversion is stored in the location referenced by | |
133 | .Fa endptr . | |
134 | .Pp | |
135 | If no conversion is performed, zero is returned and the value of | |
136 | .Fa nptr | |
137 | is stored in the location referenced by | |
138 | .Fa endptr . | |
139 | .Pp | |
140 | If the correct value would cause overflow, plus or minus | |
141 | .Dv HUGE_VAL , | |
142 | .Dv HUGE_VALF , | |
143 | or | |
144 | .Dv HUGE_VALL | |
145 | is returned (according to the sign and type of the return value), and | |
146 | .Er ERANGE | |
147 | is stored in | |
148 | .Va errno . | |
149 | If the correct value would cause underflow, zero is | |
150 | returned and | |
151 | .Er ERANGE | |
152 | is stored in | |
153 | .Va errno . | |
154 | .Sh ERRORS | |
155 | .Bl -tag -width Er | |
156 | .It Bq Er ERANGE | |
157 | Overflow or underflow occurred. | |
158 | .El | |
159 | .Sh SEE ALSO | |
160 | .Xr atof 3 , | |
161 | .Xr atoi 3 , | |
162 | .Xr atol 3 , | |
163 | .Xr strtod_l 3 , | |
164 | .Xr strtol 3 , | |
165 | .Xr strtoul 3 , | |
166 | .Xr wcstod 3 | |
167 | .Sh STANDARDS | |
168 | The | |
169 | .Fn strtod | |
170 | function | |
171 | conforms to | |
172 | .St -isoC-99 , | |
173 | with the exception of the bug noted below. | |
174 | .Sh BUGS | |
175 | These routines do not recognize the C99 ``NaN(...)'' syntax. | |
176 | .Sh AUTHORS | |
177 | The author of this software is | |
178 | .An David M. Gay . | |
179 | .Pp | |
180 | .Bd -literal | |
181 | Copyright (c) 1998 by Lucent Technologies | |
182 | All Rights Reserved | |
183 | ||
184 | Permission to use, copy, modify, and distribute this software and | |
185 | its documentation for any purpose and without fee is hereby | |
186 | granted, provided that the above copyright notice appear in all | |
187 | copies and that both that the copyright notice and this | |
188 | permission notice and warranty disclaimer appear in supporting | |
189 | documentation, and that the name of Lucent or any of its entities | |
190 | not be used in advertising or publicity pertaining to | |
191 | distribution of the software without specific, written prior | |
192 | permission. | |
193 | ||
194 | LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | |
195 | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. | |
196 | IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY | |
197 | SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
198 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER | |
199 | IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |
200 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | |
201 | THIS SOFTWARE. | |
202 | .Ed |