Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ctype(3C)

matherr(3M)

scanf(3S)

strtol(3C)

math(5)

strtod(3C)

NAME

strtod, atof − convert string to double-precision number

SYNOPSIS

#include <stdlib.h>

double strtod(const char ∗nptr, char ∗∗endptr);

double atof(const char ∗nptr);

MT-LEVEL

MT-Safe

DESCRIPTION

strtod() returns as a double-precision floating-point number the value represented by the character string pointed to by nptr. 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, then an optional exponent part including e or E followed by an optional sign, followed by an integer.  The decimal point character is defined by the program’s locale (category LC_NUMERIC).  In the "C" locale, or in a locale where the decimal point character is not defined, the decimal point character defaults to a period (.). 

If the value of endptr is not (char ∗∗)NULL, a pointer to the character terminating the scan is returned in the location pointed to by endptr. If no number can be formed, ∗endptr is set to nptr, and zero is returned.

atof(nptr) is equivalent to:
strtod(nptr, (char ∗∗)NULL). 

LC_NUMERIC
Determines how strtod and atof handle numeric formats.  In the "C" locale, numeric handling follows the U.S. rules. 

RETURN VALUES

If the correct value would cause overflow, ±HUGE is returned (according to the sign of the value), and errno is set to ERANGE. 

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

When the −Xc or −Xa compilation options are used, HUGE_VAL is returned instead of HUGE. 

If nptr is NaN, then atof() returns NaN. 

FILES

/usr/lib/locale/locale/LC_NUMERIC/numeric
LC_NUMERIC database for locale

SEE ALSO

ctype(3C), matherr(3M), scanf(3S), strtol(3C), math(5)

SunOS 5.5.1  —  Last change: 20 Feb 1994

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026