]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/strtod.3
_exit.2, bpf.2, cacheflush.2, capget.2, chdir.2, chmod.2, chroot.2, clock_getres...
[thirdparty/man-pages.git] / man3 / strtod.3
CommitLineData
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.\"
a9cd9cb7 8.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
fea681da
MK
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\" must display the following acknowledgement:
19.\" This product includes software developed by the University of
20.\" California, Berkeley and its contributors.
21.\" 4. Neither the name of the University nor the names of its contributors
22.\" may be used to endorse or promote products derived from this software
23.\" without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35.\" SUCH DAMAGE.
8c9302dc 36.\" %%%LICENSE_END
fea681da
MK
37.\"
38.\" @(#)strtod.3 5.3 (Berkeley) 6/29/91
39.\"
40.\" Modified Sun Aug 21 17:16:22 1994 by Rik Faith (faith@cs.unc.edu)
41.\" Modified Sat May 04 19:34:31 MET DST 1996 by Michael Haardt
42.\" (michael@cantor.informatik.rwth-aachen.de)
7145b9a9 43.\" Added strof, strtold, aeb, 2001-06-07
fea681da 44.\"
35deeb87 45.TH STRTOD 3 2016-12-12 "Linux" "Linux Programmer's Manual"
fea681da 46.SH NAME
c45bd688 47strtod, strtof, strtold \- convert ASCII string to floating-point number
fea681da
MK
48.SH SYNOPSIS
49.B #include <stdlib.h>
68e4db0a 50.PP
fea681da
MK
51.BI "double strtod(const char *" nptr ", char **" endptr );
52.br
53.BI "float strtof(const char *" nptr ", char **" endptr );
54.br
55.BI "long double strtold(const char *" nptr ", char **" endptr );
68e4db0a 56.PP
cc4615cc
MK
57.in -4n
58Feature Test Macro Requirements for glibc (see
59.BR feature_test_macros (7)):
60.in
e0a98111 61.ad l
68e4db0a 62.PP
cc4615cc
MK
63.BR strtof (),
64.BR strtold ():
e0a98111 65.RS 4
e464f054 66_ISOC99_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L
e0a98111 67.RE
9cc5e8b7 68.ad
fea681da
MK
69.SH DESCRIPTION
70The
e511ffb6
MK
71.BR strtod (),
72.BR strtof (),
fea681da 73and
e511ffb6 74.BR strtold ()
fea681da
MK
75functions convert the initial portion of the string pointed to by
76.I nptr
77to
9ff08aad
MK
78.IR double ,
79.IR float ,
fea681da 80and
c13182ef 81.I long double
fea681da
MK
82representation, respectively.
83
84The expected form of the (initial portion of the) string is
60a90ecd
MK
85optional leading white space as recognized by
86.BR isspace (3),
f81fb444 87an optional plus (\(aq+\(aq) or minus sign (\(aq\-\(aq) and then either
fea681da
MK
88(i) a decimal number, or (ii) a hexadecimal number,
89or (iii) an infinity, or (iv) a NAN (not-a-number).
90.LP
91A
92.I "decimal number"
aa796481 93consists of a nonempty sequence of decimal digits
a43eed0c 94possibly containing a radix character (decimal point, locale-dependent,
f81fb444
MK
95usually \(aq.\(aq), optionally followed by a decimal exponent.
96A decimal exponent consists of an \(aqE\(aq or \(aqe\(aq, followed by an
aa796481 97optional plus or minus sign, followed by a nonempty sequence of
fea681da
MK
98decimal digits, and indicates multiplication by a power of 10.
99.LP
100A
101.I "hexadecimal number"
aa796481 102consists of a "0x" or "0X" followed by a nonempty sequence of
fea681da 103hexadecimal digits possibly containing a radix character,
c13182ef
MK
104optionally followed by a binary exponent.
105A binary exponent
f81fb444 106consists of a \(aqP\(aq or \(aqp\(aq, followed by an optional
aa796481 107plus or minus sign, followed by a nonempty sequence of
fea681da
MK
108decimal digits, and indicates multiplication by a power of 2.
109At least one of radix character and binary exponent must be present.
110.LP
111An
112.I infinity
324633ae 113is either "INF" or "INFINITY", disregarding case.
fea681da
MK
114.LP
115A
116.I NAN
145fb1b4
MK
117is "NAN" (disregarding case) optionally followed by a string,
118.IR (n-char-sequence) ,
119where
120.IR n-char-sequence
121specifies in an implementation-dependent
122way the type of NAN (see NOTES).
47297adb 123.SH RETURN VALUE
fea681da
MK
124These functions return the converted value, if any.
125
126If
127.I endptr
8478ee02 128is not NULL,
fea681da
MK
129a pointer to the character after the last character used in the conversion
130is stored in the location referenced by
131.IR endptr .
132
5c61e57f
MK
133If no conversion is performed, zero is returned and (unless
134.I endptr
135is null) the value of
fea681da
MK
136.I nptr
137is stored in the location referenced by
138.IR endptr .
139
140If the correct value would cause overflow, plus or minus
141.B HUGE_VAL
142.RB ( HUGE_VALF ,
143.BR HUGE_VALL )
144is returned (according to the sign of the value), and
145.B ERANGE
146is stored in
147.IR errno .
148If the correct value would cause underflow, zero is
149returned and
150.B ERANGE
c13182ef 151is stored in
fea681da
MK
152.IR errno .
153.SH ERRORS
154.TP
155.B ERANGE
156Overflow or underflow occurred.
89a0ffe3 157.SH ATTRIBUTES
612f31e5
PH
158For an explanation of the terms used in this section, see
159.BR attributes (7).
160.TS
161allbox;
162lbw29 lb lb
163l l l.
164Interface Attribute Value
165T{
89a0ffe3
PH
166.BR strtod (),
167.BR strtof (),
89a0ffe3 168.BR strtold ()
612f31e5
PH
169T} Thread safety MT-Safe locale
170.TE
47297adb 171.SH CONFORMING TO
78c186e7
MK
172POSIX.1-2001, POSIX.1-2008, C99.
173
174.BR strtod ()
175was also described in C89.
fefe023e 176.SH NOTES
c13182ef
MK
177Since
1780 can legitimately be returned
fefe023e
MK
179on both success and failure, the calling program should set
180.I errno
c13182ef 181to 0 before the call,
fefe023e
MK
182and then determine if an error occurred by checking whether
183.I errno
c7094399 184has a nonzero value after the call.
145fb1b4
MK
185
186In the glibc implementation, the
187.IR n-char-sequence
188that optionally follows "NAN"
189is interpreted as an integer number
190(with an optional '0' or '0x' prefix to select base 8 or 16)
191that is to be placed in the
192mantissa component of the returned value.
193.\" From glibc 2.8's stdlib/strtod_l.c:
194.\" We expect it to be a number which is put in the
195.\" mantissa of the number.
196.\" It looks as though at least FreeBSD (according to the manual) does
197.\" something similar.
198.\" C11 says: "An implementation may use the n-char sequence to determine
199.\" extra information to be represented in the NaN's significant."
5a1cae6b
MK
200.SH EXAMPLE
201See the example on the
202.BR strtol (3)
c13182ef 203manual page;
5a1cae6b 204the use of the functions described in this manual page is similar.
47297adb 205.SH SEE ALSO
fea681da
MK
206.BR atof (3),
207.BR atoi (3),
208.BR atol (3),
9b944b8d
MK
209.BR nan (3),
210.BR nanf (3),
211.BR nanl (3),
b61e3789 212.BR strfromd (3),
fea681da 213.BR strtol (3),
cc4615cc 214.BR strtoul (3)