strtod(3C)


strtod, strtold, atof -- convert string to double-precision number

Synopsis

   #include <stdlib.h>
   

double strtod (const char *str, char **ptr);

long double strtold (const char *str, char **ptr);

double atof (const char *str);

Description

strtod returns as a double-precision floating-point number the value represented by the character string pointed to by str. The string is scanned up to the first unrecognized character.

strtod recognizes an optional string of ``white-space'' characters [as defined by isspace in ctype(3C)], then an optional sign, then a string of digits optionally containing a decimal-point character [as specified by the current locale; see setlocale(3C)], then an optional exponent part including an e or E followed by an optional sign, followed by an integer.

If the value of ptr is not (char **)0, a pointer to the character terminating the scan is returned in the location pointed to by ptr. If no number can be formed, *ptr is set to str, and zero is returned.

On the processors that support strtold, this function is equivalent to strtod, except that it returns a long double-precision floating-point number.

atof(str) is equivalent to:

   strtod(str, (char **)0)

Errors

If the correct value would cause overflow, a value that compares equal to ±HUGE_VAL is returned (according to the sign of the value), and errno is set to ERANGE.

If the correct value would cause underflow, zero is returned and errno is set to ERANGE.

When the -Xt compilation options are used [see cc(1)], a value that compares equal to ±HUGE is returned instead of ±HUGE_VAL.

References

cc(1), ctype(3C), fscanf(3S), setlocale(3C), strtol(3C)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004