1 /*
2 Copyright (c) 1990 Regents of the University of California.
3 All rights reserved.
4 */
5 /*
6 FUNCTION
7 <<atof>>, <<atoff>>---string to double or float
8
9 INDEX
10 atof
11 INDEX
12 atoff
13
14 SYNOPSIS
15 #include <stdlib.h>
16 double atof(const char *<[s]>);
17 float atoff(const char *<[s]>);
18
19 DESCRIPTION
20 <<atof>> converts the initial portion of a string to a <<double>>.
21 <<atoff>> converts the initial portion of a string to a <<float>>.
22
23 The functions parse the character string <[s]>,
24 locating a substring which can be converted to a floating-point
25 value. The substring must match the format:
26 . [+|-]<[digits]>[.][<[digits]>][(e|E)[+|-]<[digits]>]
27 The substring converted is the longest initial
28 fragment of <[s]> that has the expected format, beginning with
29 the first non-whitespace character. The substring
30 is empty if <<str>> is empty, consists entirely
31 of whitespace, or if the first non-whitespace character is
32 something other than <<+>>, <<->>, <<.>>, or a digit.
33
34 <<atof(<[s]>)>> is implemented as <<strtod(<[s]>, NULL)>>.
35 <<atoff(<[s]>)>> is implemented as <<strtof(<[s]>, NULL)>>.
36
37 RETURNS
38 <<atof>> returns the converted substring value, if any, as a
39 <<double>>; or <<0.0>>, if no conversion could be performed.
40 If the correct value is out of the range of representable values, plus
41 or minus <<HUGE_VAL>> is returned, and <<ERANGE>> is stored in
42 <<errno>>.
43 If the correct value would cause underflow, <<0.0>> is returned
44 and <<ERANGE>> is stored in <<errno>>.
45
46 <<atoff>> obeys the same rules as <<atof>>, except that it
47 returns a <<float>>.
48
49 PORTABILITY
50 <<atof>> is ANSI C. <<atof>>, <<atoi>>, and <<atol>> are subsumed by <<strod>>
51 and <<strol>>, but are used extensively in existing code. These functions are
52 less reliable, but may be faster if the argument is verified to be in a valid
53 range.
54
55 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
56 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
57 */
58
59
60 #include <stdlib.h>
61 #include <_ansi.h>
62
63 double
atof(const char * s)64 atof (const char *s)
65 {
66 return strtod (s, NULL);
67 }
68