Format
#include <stdlib.h>
float strtof(const char * __restrict__nptr, char ** __restrict__endptr);
General Description
The strtof() function converts part of a character string, pointed
to by nptr, to a 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 subject string is the longest string that matches the expected
form.
The expected form of the subject sequence is an optional plus or
minus sign with one of the following parts:
- A non-empty sequence of decimal digits optionally containing a
radix character followed by 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, a base 2 decimal exponent
part with a p or P as prefix, a plus or minus sign, and then a sequence
of at least one decimal digit, for example, [-]0xh.hhhhp+/-d.
- An INF, ignoring case.
- One of NANQ or NANQ(n), ignoring case.
- One of NANS or NANS(n), ignoring case.
- One of NAN or NAN(n), ignoring case.
In z/OS® Metal C, represent
the radix character as a period (.).
See sscanf() — Read and Format Data for a description of special infinity
and NAN sequences recognized by z/OS Metal
C.
The pointer to the last string that was successfully converted
is stored in the object pointed to by endptr, if endptr is
not a NULL pointer. If the subject string is empty or it does not
have the expected form, no conversion is performed. The value of nptr is
stored in the object pointed to by endptr.
Returned Value
If successful, strtof() returns the value of the floating-point
number in IEEE Binary Floating-Point format.
In an overflow, strtof() returns +/-HUGE_VALF. In an underflow,
it returns 0. If no conversion is performed, strtof() returns 0.