strtod(3C) Standard C Library Functions strtod(3C)
NAME
strtod, strtof, strtold, atof - convert string to floating-point number
SYNOPSIS
#include <stdlib.h>
double strtod(const char *restrict nptr, char **restrict endptr);
float strtof(const char *restrict nptr, char **restrict endptr);
long double strtold(const char *restrict nptr, char **restrict endptr);
double atof(const char *str);
DESCRIPTION
The strtod(), strtof(), and strtold() functions convert the initial portion of the string pointed to by nptr to double, float, and long
double representation, respectively. First they decompose the input string into three parts:
1. An initial, possibly empty, sequence of white-space characters (as specified by isspace(3C))
2. A subject sequence interpreted as a floating-point constant or representing infinity or NaN
3. A final string of one or more unrecognized characters, including the terminating null byte of the input string.
Then they attempt to convert the subject sequence to a floating-point number, and return the result.
The expected form of the subject sequence is an optional plus or minus sign, then one of the following:
o A non-empty sequence of digits optionally containing a radix character, then an optional exponent part
o A 0x or 0X, then a non-empty sequence of hexadecimal digits optionally containing a radix character, then an optional binary exponent
part
o One of INF or INFINITY, ignoring case
o One of NAN or NAN(n-char-sequenceopt), ignoring case in the NAN part, where:
n-char-sequence:
digit
nondigit
n-char-sequence digit
n-char-sequence nondigit
In default mode for strtod(), only decimal, INF/INFINITY, and NAN/NAN(n-char-sequence) forms are recognized. In C99/SUSv3 mode, hexadecimal
strings are also recognized.
In default mode for strtod(), the n-char-sequence in the NAN(n-char-equence) form can contain any character except ')' (right parenthesis)
or '