]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" 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 5.3 (Berkeley) 6/29/91 | |
37 | .\" | |
38 | .\" Modified Sun Aug 21 17:16:22 1994 by Rik Faith (faith@cs.unc.edu) | |
39 | .\" Modified Sat May 04 19:34:31 MET DST 1996 by Michael Haardt | |
40 | .\" (michael@cantor.informatik.rwth-aachen.de) | |
7145b9a9 | 41 | .\" Added strof, strtold, aeb, 2001-06-07 |
fea681da | 42 | .\" |
50831f9b | 43 | .TH STRTOD 3 2010-09-20 "Linux" "Linux Programmer's Manual" |
fea681da | 44 | .SH NAME |
c45bd688 | 45 | strtod, strtof, strtold \- convert ASCII string to floating-point number |
fea681da MK |
46 | .SH SYNOPSIS |
47 | .B #include <stdlib.h> | |
48 | .sp | |
49 | .BI "double strtod(const char *" nptr ", char **" endptr ); | |
50 | .br | |
51 | .BI "float strtof(const char *" nptr ", char **" endptr ); | |
52 | .br | |
53 | .BI "long double strtold(const char *" nptr ", char **" endptr ); | |
cc4615cc MK |
54 | .sp |
55 | .in -4n | |
56 | Feature Test Macro Requirements for glibc (see | |
57 | .BR feature_test_macros (7)): | |
58 | .in | |
e0a98111 | 59 | .ad l |
cc4615cc MK |
60 | .sp |
61 | .BR strtof (), | |
62 | .BR strtold (): | |
e0a98111 | 63 | .RS 4 |
6c3f0228 MK |
64 | _XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE || |
65 | _POSIX_C_SOURCE\ >=\ 200112L; | |
e0a98111 MK |
66 | .br |
67 | or | |
cc4615cc | 68 | .I cc\ -std=c99 |
e0a98111 MK |
69 | .RE |
70 | .ad l | |
fea681da MK |
71 | .SH DESCRIPTION |
72 | The | |
e511ffb6 MK |
73 | .BR strtod (), |
74 | .BR strtof (), | |
fea681da | 75 | and |
e511ffb6 | 76 | .BR strtold () |
fea681da MK |
77 | functions convert the initial portion of the string pointed to by |
78 | .I nptr | |
79 | to | |
9ff08aad MK |
80 | .IR double , |
81 | .IR float , | |
fea681da | 82 | and |
c13182ef | 83 | .I long double |
fea681da MK |
84 | representation, respectively. |
85 | ||
86 | The expected form of the (initial portion of the) string is | |
60a90ecd MK |
87 | optional leading white space as recognized by |
88 | .BR isspace (3), | |
f81fb444 | 89 | an optional plus (\(aq+\(aq) or minus sign (\(aq\-\(aq) and then either |
fea681da MK |
90 | (i) a decimal number, or (ii) a hexadecimal number, |
91 | or (iii) an infinity, or (iv) a NAN (not-a-number). | |
92 | .LP | |
93 | A | |
94 | .I "decimal number" | |
aa796481 | 95 | consists of a nonempty sequence of decimal digits |
a43eed0c | 96 | possibly containing a radix character (decimal point, locale-dependent, |
f81fb444 MK |
97 | usually \(aq.\(aq), optionally followed by a decimal exponent. |
98 | A decimal exponent consists of an \(aqE\(aq or \(aqe\(aq, followed by an | |
aa796481 | 99 | optional plus or minus sign, followed by a nonempty sequence of |
fea681da MK |
100 | decimal digits, and indicates multiplication by a power of 10. |
101 | .LP | |
102 | A | |
103 | .I "hexadecimal number" | |
aa796481 | 104 | consists of a "0x" or "0X" followed by a nonempty sequence of |
fea681da | 105 | hexadecimal digits possibly containing a radix character, |
c13182ef MK |
106 | optionally followed by a binary exponent. |
107 | A binary exponent | |
f81fb444 | 108 | consists of a \(aqP\(aq or \(aqp\(aq, followed by an optional |
aa796481 | 109 | plus or minus sign, followed by a nonempty sequence of |
fea681da MK |
110 | decimal digits, and indicates multiplication by a power of 2. |
111 | At least one of radix character and binary exponent must be present. | |
112 | .LP | |
113 | An | |
114 | .I infinity | |
324633ae | 115 | is either "INF" or "INFINITY", disregarding case. |
fea681da MK |
116 | .LP |
117 | A | |
118 | .I NAN | |
f81fb444 MK |
119 | is "NAN" (disregarding case) optionally followed by \(aq(\(aq, |
120 | a sequence of characters, followed by \(aq)\(aq. | |
fea681da MK |
121 | The character string specifies in an implementation-dependent |
122 | way the type of NAN. | |
ba00ca74 MK |
123 | .\" From glibc 2.8's stdlib/strtod_l.c: |
124 | .\" We expect it to be a number which is put in the | |
125 | .\" mantissa of the number. | |
47297adb | 126 | .SH RETURN VALUE |
fea681da MK |
127 | These functions return the converted value, if any. |
128 | ||
129 | If | |
130 | .I endptr | |
8478ee02 | 131 | is not NULL, |
fea681da MK |
132 | a pointer to the character after the last character used in the conversion |
133 | is stored in the location referenced by | |
134 | .IR endptr . | |
135 | ||
136 | If no conversion is performed, zero is returned and the value of | |
137 | .I nptr | |
138 | is stored in the location referenced by | |
139 | .IR endptr . | |
140 | ||
141 | If the correct value would cause overflow, plus or minus | |
142 | .B HUGE_VAL | |
143 | .RB ( HUGE_VALF , | |
144 | .BR HUGE_VALL ) | |
145 | is returned (according to the sign of the value), and | |
146 | .B ERANGE | |
147 | is stored in | |
148 | .IR errno . | |
149 | If the correct value would cause underflow, zero is | |
150 | returned and | |
151 | .B ERANGE | |
c13182ef | 152 | is stored in |
fea681da MK |
153 | .IR errno . |
154 | .SH ERRORS | |
155 | .TP | |
156 | .B ERANGE | |
157 | Overflow or underflow occurred. | |
47297adb | 158 | .SH CONFORMING TO |
68e1685c | 159 | C89 describes |
e511ffb6 | 160 | .BR strtod (), |
fea681da MK |
161 | C99 |
162 | describes the other two functions. | |
fefe023e | 163 | .SH NOTES |
c13182ef MK |
164 | Since |
165 | 0 can legitimately be returned | |
fefe023e MK |
166 | on both success and failure, the calling program should set |
167 | .I errno | |
c13182ef | 168 | to 0 before the call, |
fefe023e MK |
169 | and then determine if an error occurred by checking whether |
170 | .I errno | |
c7094399 | 171 | has a nonzero value after the call. |
5a1cae6b MK |
172 | .SH EXAMPLE |
173 | See the example on the | |
174 | .BR strtol (3) | |
c13182ef | 175 | manual page; |
5a1cae6b | 176 | the use of the functions described in this manual page is similar. |
47297adb | 177 | .SH SEE ALSO |
fea681da MK |
178 | .BR atof (3), |
179 | .BR atoi (3), | |
180 | .BR atol (3), | |
181 | .BR strtol (3), | |
cc4615cc | 182 | .BR strtoul (3) |