strtof() — Convert character string to float
|Standards / Extensions||C or C++||Dependencies|
Single UNIX Specification, Version 3
C++ TR1 C99
#define _ISOC99_SOURCE #include <stdlib.h> float strtof(const char *__restrict__ nptr, char **__restrict__ endptr);
strtof() converts a part of a character string, pointed to by nptr, to float. The parameter nptr points to a sequence of characters that can be interpreted as a numerical value of the type float.
The strtof() function breaks the string into three parts:
- An initial, possibly empty, sequence of white-space characters (as specified by isspace()).
- A subject sequence interpreted as a floating-point constant or representing infinity or a NAN.
- A final string of one or more unrecognized characters, including the terminating null byte of the input string.
The function then attempts to convert the subject string into the floating-point number, and returns the result.
The expected form of the subject sequence is an optional plus or minus sign, then one of the following:
- A non-empty sequence of decimal digits optionally containing a radix character, then an optional exponent part. A radix character is the character that separates the integer part of a number from the fractional part.
- A 0x or 0X, a non-empty sequence of hexadecimal digits optionally containing a radix character, then a base 2 decimal exponent part with a p or P as prefix, a plus or minus sign, then a sequence of at least one decimal digit. (Example [-]0xh.hhhhp+/-d). A radix character is the character that separates the integer part of a number from the fractional part.
- One of INF or INFINITY, ignoring case.
- One of NANQ or NANQ(n-char-sequence), ignoring case.
- One of NANS or NANS(n-char-sequence), ignoring case.
- One of NAN or NAN(n-char-sequence), ignoring case.
See the "scanf Family of Formatted Input Functions" for a description of special infinity and NaN sequences recognized by z/OS formatted input functions in IEEE Binary Floating-Point mode.
The pointer to the last string successfully converted is stored in the object pointed to by endptr, provided that endptr is not a NULL pointer. If the subject string is empty or it does not have the expected form, then no conversion is performed. The value of nptr is stored in the object pointed to by endptr.
If successful, strtof() returns the value of the floating-point number.
The float value is hexadecimal floating-point or IEEE Binary Floating-Point format depending on the floating-point mode of the thread invoking the strtof() function. This function uses __isBFP() to determine the floating-point mode of the invoking thread.
In an overflow, strtof() returns +/-HUGE_VALF. In an underflow, it returns 0. If no conversion is performed, strtof() returns 0. In both cases, errno is set to ERANGE, depending on the base of the value.
- stdlib.h — Standard library functions
- atof() — Convert character string to double
- atoi() — Convert character string to integer
- atol() — Convert character string to long
- fscanf(), scanf(), sscanf() — Read and format data
- __isBFP() — Determine application floating-point format
- strtod() — Convert character string to double
- strtold() — Convert character string to long double
- strtol() — Convert character string to long
- strtoul() — Convert string to unsigned integer