1STRTOD(3) Linux Programmer's Manual STRTOD(3)
2
3
4
6 strtod, strtof, strtold - convert ASCII string to floating-point number
7
9 #include <stdlib.h>
10
11 double strtod(const char *nptr, char **endptr);
12 float strtof(const char *nptr, char **endptr);
13 long double strtold(const char *nptr, char **endptr);
14
15 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17 strtof(), strtold(): _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE; or
18 cc -std=c99
19
21 The strtod(), strtof(), and strtold() functions convert the initial
22 portion of the string pointed to by nptr to double, float, and long
23 double representation, respectively.
24
25 The expected form of the (initial portion of the) string is optional
26 leading white space as recognized by isspace(3), an optional plus ('+')
27 or minus sign ('-') and then either (i) a decimal number, or (ii) a
28 hexadecimal number, or (iii) an infinity, or (iv) a NAN (not-a-number).
29
30 A decimal number consists of a non-empty sequence of decimal digits
31 possibly containing a radix character (decimal point, locale-dependent,
32 usually '.'), optionally followed by a decimal exponent. A decimal
33 exponent consists of an 'E' or 'e', followed by an optional plus or
34 minus sign, followed by a non-empty sequence of decimal digits, and
35 indicates multiplication by a power of 10.
36
37 A hexadecimal number consists of a "0x" or "0X" followed by a non-empty
38 sequence of hexadecimal digits possibly containing a radix character,
39 optionally followed by a binary exponent. A binary exponent consists
40 of a 'P' or 'p', followed by an optional plus or minus sign, followed
41 by a non-empty sequence of decimal digits, and indicates multiplication
42 by a power of 2. At least one of radix character and binary exponent
43 must be present.
44
45 An infinity is either "INF" or "INFINITY", disregarding case.
46
47 A NAN is "NAN" (disregarding case) optionally followed by '(', a
48 sequence of characters, followed by ')'. The character string speci‐
49 fies in an implementation-dependent way the type of NAN.
50
52 These functions return the converted value, if any.
53
54 If endptr is not NULL, a pointer to the character after the last char‐
55 acter used in the conversion is stored in the location referenced by
56 endptr.
57
58 If no conversion is performed, zero is returned and the value of nptr
59 is stored in the location referenced by endptr.
60
61 If the correct value would cause overflow, plus or minus HUGE_VAL
62 (HUGE_VALF, HUGE_VALL) is returned (according to the sign of the
63 value), and ERANGE is stored in errno. If the correct value would
64 cause underflow, zero is returned and ERANGE is stored in errno.
65
67 ERANGE Overflow or underflow occurred.
68
70 C89 describes strtod(), C99 describes the other two functions.
71
73 Since 0 can legitimately be returned on both success and failure, the
74 calling program should set errno to 0 before the call, and then deter‐
75 mine if an error occurred by checking whether errno has a non-zero
76 value after the call.
77
79 See the example on the strtol(3) manual page; the use of the functions
80 described in this manual page is similar.
81
83 atof(3), atoi(3), atol(3), strtol(3), strtoul(3)
84
86 This page is part of release 3.22 of the Linux man-pages project. A
87 description of the project, and information about reporting bugs, can
88 be found at http://www.kernel.org/doc/man-pages/.
89
90
91
92Linux 2007-07-26 STRTOD(3)