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