1STRTOD(3)                  Linux Programmer's Manual                 STRTOD(3)
2
3
4

NAME

6       strtod, strtof, strtold - convert ASCII string to floating-point number
7

SYNOPSIS

9       #include <stdlib.h>
10
11       double strtod(const char *restrict nptr, char **restrict endptr);
12       float strtof(const char *restrict nptr, char **restrict endptr);
13       long double strtold(const char *restrict nptr, char **restrict endptr);
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       strtof(), strtold():
18           _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
19

DESCRIPTION

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 nonempty sequence of decimal digits pos‐
31       sibly  containing  a  radix character (decimal point, locale-dependent,
32       usually '.'), optionally followed by a decimal exponent.  A decimal ex‐
33       ponent consists of an 'E' or 'e', followed by an optional plus or minus
34       sign, followed by a nonempty sequence of decimal digits, and  indicates
35       multiplication by a power of 10.
36
37       A  hexadecimal number consists of a "0x" or "0X" followed by a nonempty
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 nonempty 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 string, (n-
48       char-sequence), where n-char-sequence specifies in  an  implementation-
49       dependent way the type of NAN (see NOTES).
50

RETURN VALUE

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 (unless endptr is
59       null) the value of nptr 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,  or  HUGE_VALL is returned (according to the return type and
63       sign of the value), and ERANGE is stored in errno.
64
65       If the correct value would cause underflow, a value with  magnitude  no
66       larger  than  DBL_MIN,  FLT_MIN,  or LDBL_MIN is returned and ERANGE is
67       stored in errno.
68

ERRORS

70       ERANGE Overflow or underflow occurred.
71

ATTRIBUTES

73       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
74       tributes(7).
75
76       ┌─────────────────────────────────────┬───────────────┬────────────────┐
77Interface                            Attribute     Value          
78       ├─────────────────────────────────────┼───────────────┼────────────────┤
79strtod(), strtof(), strtold()        │ Thread safety │ MT-Safe locale │
80       └─────────────────────────────────────┴───────────────┴────────────────┘
81

CONFORMING TO

83       POSIX.1-2001, POSIX.1-2008, C99.
84
85       strtod() was also described in C89.
86

NOTES

88       Since  0  can legitimately be returned on both success and failure, the
89       calling program should set errno to 0 before the call, and then  deter‐
90       mine if an error occurred by checking whether errno has a nonzero value
91       after the call.
92
93       In the glibc implementation, the n-char-sequence that  optionally  fol‐
94       lows "NAN" is interpreted as an integer number (with an optional '0' or
95       '0x' prefix to select base 8 or 16) that is to be placed in the mantis‐
96       sa component of the returned value.
97

EXAMPLES

99       See  the example on the strtol(3) manual page; the use of the functions
100       described in this manual page is similar.
101

SEE ALSO

103       atof(3), atoi(3), atol(3), nan(3), nanf(3), nanl(3), strfromd(3),  str‐
104       tol(3), strtoul(3)
105

COLOPHON

107       This  page  is  part of release 5.12 of the Linux man-pages project.  A
108       description of the project, information about reporting bugs,  and  the
109       latest     version     of     this    page,    can    be    found    at
110       https://www.kernel.org/doc/man-pages/.
111
112
113
114Linux                             2021-03-22                         STRTOD(3)
Impressum