Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > S

strtod(3C)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

strtod(), strtof(), strtold(), strtow(), strtoq(), atof() — convert string to floating-point number

SYNOPSIS

#include <stdlib.h>

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

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

double atof(const char *str);

Itanium(R)-based Systems Only

float strtof(const char *__restrict str, char **__restrict ptr);

extended strtow(const char *str, char **ptr);

quad strtoq(const char *str, char **ptr);

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 (leading white-space characters as defined by isspace() in ctype(3C) are ignored) up to the first unrecognized character. If no conversion can take place, zero is returned.

strtod() recognizes characters in the following sequence:

1.

An optional string of white space characters which are ignored

2.

An optional sign

and one of the following:

3.

A string of digits optionally containing a radix character, followed by an optional e or E, followed by an optional sign or space, followed by an integer

4.

One of INF or INFINITY, ignoring case

5.

NAN, ignoring case

6.

For Itanium-based system only: 0x or 0X, then a nonempty sequence of hexadecimal digits optionally containing a radix character, then a p or P, followed by an optional sign or space, followed by a decimal integer

The radix character is determined by the loaded NLS environment (see setlocale(3C)). If setlocale() has not been called successfully, the default NLS environment, "C", is used (see lang(5)). The default environment specifies a period (.) as the radix character.

In the hexadecimal form, the optionally signed decimal integer following the p or P is interpreted as the power of 2 by which the significant part is to be scaled.

If the value of ptr is not (char **)NULL, the variable to which it points is set to point at the character after the last number, if any, that was recognized. If no number can be formed, *ptr is set to str, and zero is returned.

atof(str) is equivalent to strtod (str, (char **)NULL).

strtold() is a long double version of strtod(); it returns a long double result. For PA-RISC and for Itanium-based systems, if the user has defined _LONG_DOUBLE_STRUCT, the result type is declared as a struct, instead of as a long double. The declaration with a struct is obsolescent.

Itanium-based Systems Only

strtof() is a float version of strtod(); it returns a float result.

strtow() is an extended version of strtod(); it returns an extended result.

strtoq() is equivalent to strtold().

EXTERNAL INFLUENCES

Environment Variables

LC_NUMERIC determines the value of the radix character within the currently loaded NLS environment.

APPLICATION USAGE

To use (for Itanium-based systems) strtow() or strtoq(), compile with the -fpwidetypes option.

RETURN VALUE

If the correct value would cause overflow, strtod() returns +/-HUGE_VAL (equal to +/-INFINITY), according to the sign of the value, and sets errno to ERANGE.

If the correct value would be nonzero but too small in magnitude to represent as a nonzero double, then strtod() returns zero and sets errno to ERANGE. For Itanium-based system, strtod() also sets errno to ERANGE whenever the conversion of its input parameter character string to double raises the underflow exception.

When the input parameter character string for strtod(), after the optional white space and sign, is either INF (case insensitive) or INFINITY (case insensitive) strtod() will return +/-INFINITY, according to the sign indicated by the character string.

When the input parameter character string for strtod(), after the optional white space and sign, is NAN (case insensitive), strtod() will return a quiet NaN.

On Itanium-based systems, these functions round correctly for hexadecimal input strings, and round correctly for up to 36 significant decimal digits, according to the specification in ISO/IEC C99.

STANDARDS CONFORMANCE

strtod(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, ANSI C

atof(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.