Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ strtod(3C) — sys5 — Apollo Domain/OS SR10.4.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

atoi(3C)

setlocale(3C)

scanf(3S)

STRTOD(3C)                           SysV                           STRTOD(3C)



NAME
     atof, strtod - Converts a character string to a double-precision
     floating-point value

SYNOPSIS
     #include <stdlib.h>

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

     double atof (str)
     const char *str;

DESCRIPTION
     The atof function converts the string pointed to by the nptr argument up
     to the first character that is inconsistent with the format of a
     floating-point number to a double floating-point value. Leading white-
     space characters are ignored.  A call to this function is equivalent to a
     call to strtod(nptr, (char **) NULL), except for error handling.  When
     the value cannot be represented, the result is undefined.

     The strtod function converts the initial portion of the string pointed to
     by the nptr argument to double representation.  First the input string is
     decomposed into the following three parts:

     +    An initial, possibly empty, sequence of white-space characters (as
          specified by the isspace(3C) function).

     +    A subject sequence interpreted as a floating-point constant.

     +    A final string of one or more unrecognized characters, including the
          terminating null character of the input string.

     After decomposition of the string, the subject sequence is converted to a
     floating-point number, and the resulting value is returned.  A subject
     sequence is defined as the longest initial subsequence of the input
     string, starting with the first nonwhite-space character, that is of the
     expected form. The expected form and order of the subject sequence is:

     +    An optional plus (+) or minus (-) sign.

     +    A  sequence of digits optionally containing a radix character.

     +    An optional exponent part. An exponent part consists of e or E,
          followed by an optional sign, which is followed by one or more
          decimal digits.

     When the input string is empty or consists entirely of white space, or
     when the first nonwhite-space character is other than a sign, a digit, or
     a radix character, the subject sequence contains no characters.

     For the strtod function, when the value of the endptr argument is not
     (char**) NULL, a pointer to the character that terminated the scan is
     stored at *endptr.

     When a floating-point value cannot be formed, *endptr is set to nptr.
     The setlocale(3C) function may affect the radix character used in the
     conversion result.

     The radix character is defined by langinfo data in the program's locale
     (category LC_NUMERIC).

DIAGNOSTICS
     The strtod function returns the converted value, if any. If no conversion
     could be performed, zero is returned.

     When a correct return value overflows, a properly signed HUGE_VAL (INF)
     is returned and errno is set to indicate the error.

     On underflow, zero is returned and errno is set to indicate the error.

     The atof function returns the converted value. If no conversion could be
     performed, the behavior is undefined.

ERRORS
     If the atof or strtod function fails, errno will be set to the following
     value:

     [ERANGE]  The input string is out of range (that is, the subject sequence
               can not be converted to a floating-point value without causing
               underflow or overflow).

SEE ALSO
     atoi(3C), setlocale(3C), scanf(3S) <stdio.h>

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