1strtod(3)                  Library Functions Manual                  strtod(3)
2
3
4

NAME

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

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

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

DESCRIPTION

24       The  strtod(),  strtof(),  and  strtold() functions convert the initial
25       portion of the string pointed to by nptr to  double,  float,  and  long
26       double representation, respectively.
27
28       The  expected  form  of the (initial portion of the) string is optional
29       leading white space as recognized by isspace(3), an optional plus ('+')
30       or  minus  sign  ('-')  and then either (i) a decimal number, or (ii) a
31       hexadecimal number, or (iii) an infinity, or (iv) a NAN (not-a-number).
32
33       A decimal number consists of a nonempty sequence of decimal digits pos‐
34       sibly  containing  a  radix character (decimal point, locale-dependent,
35       usually '.'), optionally followed by a decimal exponent.  A decimal ex‐
36       ponent consists of an 'E' or 'e', followed by an optional plus or minus
37       sign, followed by a nonempty sequence of decimal digits, and  indicates
38       multiplication by a power of 10.
39
40       A  hexadecimal number consists of a "0x" or "0X" followed by a nonempty
41       sequence of hexadecimal digits possibly containing a  radix  character,
42       optionally  followed  by a binary exponent.  A binary exponent consists
43       of a 'P' or 'p', followed by an optional plus or minus  sign,  followed
44       by  a nonempty sequence of decimal digits, and indicates multiplication
45       by a power of 2.  At least one of radix character and  binary  exponent
46       must be present.
47
48       An infinity is either "INF" or "INFINITY", disregarding case.
49
50       A NAN is "NAN" (disregarding case) optionally followed by a string, (n-
51       char-sequence), where n-char-sequence specifies in  an  implementation-
52       dependent way the type of NAN (see NOTES).
53

RETURN VALUE

55       These functions return the converted value, if any.
56
57       If  endptr is not NULL, a pointer to the character after the last char‐
58       acter used in the conversion is stored in the  location  referenced  by
59       endptr.
60
61       If  no  conversion is performed, zero is returned and (unless endptr is
62       null) the value of nptr is stored in the location referenced by endptr.
63
64       If the correct value would cause  overflow,  plus  or  minus  HUGE_VAL,
65       HUGE_VALF,  or  HUGE_VALL is returned (according to the return type and
66       sign of the value), and ERANGE is stored in errno.
67
68       If the correct value would cause underflow, a value with  magnitude  no
69       larger  than  DBL_MIN,  FLT_MIN,  or LDBL_MIN is returned and ERANGE is
70       stored in errno.
71

ERRORS

73       ERANGE Overflow or underflow occurred.
74

ATTRIBUTES

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

VERSIONS

86       In  the  glibc implementation, the n-char-sequence that optionally fol‐
87       lows "NAN" is interpreted as an integer number (with an optional '0' or
88       '0x' prefix to select base 8 or 16) that is to be placed in the mantis‐
89       sa component of the returned value.
90

STANDARDS

92       C11, POSIX.1-2008.
93

HISTORY

95       strtod()
96              C89, POSIX.1-2001.
97
98       strtof()
99       strtold()
100              C99, POSIX.1-2001.
101

NOTES

103       Since 0 can legitimately be returned on both success and  failure,  the
104       calling  program should set errno to 0 before the call, and then deter‐
105       mine if an error occurred by checking whether errno has a nonzero value
106       after the call.
107

EXAMPLES

109       See  the example on the strtol(3) manual page; the use of the functions
110       described in this manual page is similar.
111

SEE ALSO

113       atof(3), atoi(3), atol(3), nan(3), nanf(3), nanl(3), strfromd(3),  str‐
114       tol(3), strtoul(3)
115
116
117
118Linux man-pages 6.04              2023-03-30                         strtod(3)
Impressum