_atold -- Convert Character String to Long Double

Format

#include <stdlib.h>    /* also defined in <math.h> */
long double _atold(const char *nptr);

Language Level: Extension
_atold converts a character string pointed to by nptr to a long double value. The function continues until it reads a character it does not recognize as part of a number. This character can be the ending null character. Except for its behavior on error, _atold is equivalent to:

strtold(nptr, (char **)NULL)

The string pointed to by nptr must have the following format:

digits is one or more decimal digits. If no digits appear before the decimal point, at least one digit must follow the decimal point. You can place an exponent expressed as a decimal integer after the digits. The exponent can be signed.

The value of nptr can also be one of the strings infinity, inf, or nan. These strings are case insensitive, and can be preceded by a unary minus (-). They are converted to infinity and NaN values.

_atold ignores any white-space characters, as defined by the isspace function.

Return Value
_atold returns the converted long double value. In the case of an underflow, it returns 0. In the case of a positive overflow, _atold returns positive _LHUGE_VAL. It returns negative _LHUGE_VAL for a negative overflow.

Example
This example uses _atold to convert two strings, " -001234.5678e10end of string" and "NaNQ", to their corresponding long double values.

#include <stdlib.h>
#include <stdio.h>
int main(void)
{
   char *string;
   string = "  -001234.5678e10end of string";
   printf("_atold = %.10Le\n", _atold(string));
   string = "NaNQ";
   printf("_atold = %.10Le\n", _atold(string));
   return 0;
   /*********************************************
      The output should be:
      _atold = -1.2345678000e+13
      _atold = nan
   *********************************************/
}



atof -- Convert Character String to Float
atoi -- Convert Character String to Integer
atol -- Convert Character String to Long Integer
strtod -- Convert Character String to Double
strtol -- Convert Character String to Long Integer
strtold -- Convert String to Long Double
<stdlib.h>
<math.h>