2 .\" Copyright (c) 1990, 1991 The Regents of the University of California.
3 .\" All rights reserved.
5 .\" This code is derived from software contributed to Berkeley by
6 .\" the American National Standards Committee X3, on Information
7 .\" Processing Systems.
9 .\" SPDX-License-Identifier: BSD-4-Clause-UC
11 .\" @(#)strtod.3 5.3 (Berkeley) 6/29/91
13 .\" Modified Sun Aug 21 17:16:22 1994 by Rik Faith (faith@cs.unc.edu)
14 .\" Modified Sat May 04 19:34:31 MET DST 1996 by Michael Haardt
15 .\" (michael@cantor.informatik.rwth-aachen.de)
16 .\" Added strof, strtold, aeb, 2001-06-07
18 .TH strtod 3 (date) "Linux man-pages (unreleased)"
20 strtod, strtof, strtold \- convert ASCII string to floating-point number
23 .RI ( libc ", " \-lc )
26 .B #include <stdlib.h>
28 .BI "double strtod(const char *restrict " nptr ", char **restrict " endptr );
29 .BI "float strtof(const char *restrict " nptr ", char **restrict " endptr );
30 .BI "long double strtold(const char *restrict " nptr \
31 ", char **restrict " endptr );
35 Feature Test Macro Requirements for glibc (see
36 .BR feature_test_macros (7)):
42 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
50 functions convert the initial portion of the string pointed to by
57 representation, respectively.
59 The expected form of the (initial portion of the) string is
60 optional leading white space as recognized by
62 an optional plus (\[aq]+\[aq]) or minus sign (\[aq]\-\[aq]) and then either
63 (i) a decimal number, or (ii) a hexadecimal number,
64 or (iii) an infinity, or (iv) a NAN (not-a-number).
68 consists of a nonempty sequence of decimal digits
69 possibly containing a radix character (decimal point, locale-dependent,
70 usually \[aq].\[aq]), optionally followed by a decimal exponent.
71 A decimal exponent consists of an \[aq]E\[aq] or \[aq]e\[aq], followed by an
72 optional plus or minus sign, followed by a nonempty sequence of
73 decimal digits, and indicates multiplication by a power of 10.
76 .I "hexadecimal number"
77 consists of a "0x" or "0X" followed by a nonempty sequence of
78 hexadecimal digits possibly containing a radix character,
79 optionally followed by a binary exponent.
81 consists of a \[aq]P\[aq] or \[aq]p\[aq], followed by an optional
82 plus or minus sign, followed by a nonempty sequence of
83 decimal digits, and indicates multiplication by a power of 2.
84 At least one of radix character and binary exponent must be present.
88 is either "INF" or "INFINITY", disregarding case.
92 is "NAN" (disregarding case) optionally followed by a string,
93 .IR (n-char-sequence) ,
96 specifies in an implementation-dependent
97 way the type of NAN (see NOTES).
99 These functions return the converted value, if any.
104 a pointer to the character after the last character used in the conversion
105 is stored in the location referenced by
108 If no conversion is performed, zero is returned and (unless
110 is null) the value of
112 is stored in the location referenced by
115 If the correct value would cause overflow, plus or minus
120 is returned (according to the return type and sign of the value),
126 If the correct value would cause underflow,
127 a value with magnitude no larger than
139 Overflow or underflow occurred.
141 For an explanation of the terms used in this section, see
149 Interface Attribute Value
154 T} Thread safety MT-Safe locale
160 POSIX.1-2001, POSIX.1-2008, C99.
163 0 can legitimately be returned
164 on both success and failure, the calling program should set
166 to 0 before the call,
167 and then determine if an error occurred by checking whether
169 has a nonzero value after the call.
171 In the glibc implementation, the
173 that optionally follows "NAN"
174 is interpreted as an integer number
175 (with an optional '0' or '0x' prefix to select base 8 or 16)
176 that is to be placed in the
177 mantissa component of the returned value.
178 .\" From glibc 2.8's stdlib/strtod_l.c:
179 .\" We expect it to be a number which is put in the
180 .\" mantissa of the number.
181 .\" It looks as though at least FreeBSD (according to the manual) does
182 .\" something similar.
183 .\" C11 says: "An implementation may use the n-char sequence to determine
184 .\" extra information to be represented in the NaN's significant."
186 See the example on the
189 the use of the functions described in this manual page is similar.