Borland C++ reference

atof, _atold

raw OCR

Converts a string to a floating-point number.

Defined in header <math.h>

Syntax

#include <math.h>
double  atof(const char *s);
long double  _atold(const char *s);

Portability

DOSUNIXWindowsANSI CC++ only
atof ■■■■
atold ■■

Remarks

atof converts a string pointed to by s to double; this function recognizes the character representation of a floating-point number, made up of the following:

■ an optional string of tabs and spaces. ■ an optional sign. ■ a string of digits and an optional decimal point (the digits can be on both sides of the decimal point), ■ an optional e or £ followed by an optional signed integer.

The characters must match this generic format:

[whitespace] [sign] [ddd] [.] [ddd] [e I E[sign]ddd]

atof also recognizes +INF and -INF for plus and minus infinity, and +NAN and -NAN for Not-a-Number.

In this function, the first unrecognized character ends the conversion.

_atold is the long double version; it converts the string pointed to by s to a long double.

strtod and _strtold are similar to atof and _atold; they provide better error detection, and hence are preferred in some applications.

Return value

atof and _atold return the converted value of the input string.

If there is an overflow, atof (or _atold) returns plus or minus HUGE_VAL

(or _LHUGE_VAL),errno is set to ERANGE,and matherr (or _matherrl) is

not called.

See also

Example

iinclude <stdlib.h>
#include <stdio.h>

int main(void)
{
   float f;
   char *str = "12345.678"
f = atof (str);
printf("string = %s float  = %5.3f\n", str, f);

return

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.