diff options
Diffstat (limited to 'src/lib/libc/stdlib/strtod.3')
-rw-r--r-- | src/lib/libc/stdlib/strtod.3 | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/src/lib/libc/stdlib/strtod.3 b/src/lib/libc/stdlib/strtod.3 new file mode 100644 index 0000000000..979334203e --- /dev/null +++ b/src/lib/libc/stdlib/strtod.3 | |||
@@ -0,0 +1,129 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
2 | .\" All rights reserved. | ||
3 | .\" | ||
4 | .\" This code is derived from software contributed to Berkeley by | ||
5 | .\" the American National Standards Committee X3, on Information | ||
6 | .\" Processing Systems. | ||
7 | .\" | ||
8 | .\" Redistribution and use in source and binary forms, with or without | ||
9 | .\" modification, are permitted provided that the following conditions | ||
10 | .\" are met: | ||
11 | .\" 1. Redistributions of source code must retain the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer. | ||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer in the | ||
15 | .\" documentation and/or other materials provided with the distribution. | ||
16 | .\" 3. Neither the name of the University nor the names of its contributors | ||
17 | .\" may be used to endorse or promote products derived from this software | ||
18 | .\" without specific prior written permission. | ||
19 | .\" | ||
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
30 | .\" SUCH DAMAGE. | ||
31 | .\" | ||
32 | .\" $OpenBSD: strtod.3,v 1.12 2008/06/13 23:50:49 jmc Exp $ | ||
33 | .\" | ||
34 | .Dd $Mdocdate: June 13 2008 $ | ||
35 | .Dt STRTOD 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm strtod , | ||
39 | .Nm strtof | ||
40 | .Nd convert | ||
41 | .Tn ASCII | ||
42 | string to double or float | ||
43 | .Sh SYNOPSIS | ||
44 | .Fd #include <math.h> | ||
45 | .Fd #include <stdlib.h> | ||
46 | .Ft double | ||
47 | .Fn strtod "const char *nptr" "char **endptr" | ||
48 | .Pp | ||
49 | .Ft float | ||
50 | .Fn strtof "const char *nptr" "char **endptr" | ||
51 | .Sh DESCRIPTION | ||
52 | The | ||
53 | .Fn strtod | ||
54 | function converts the initial portion of the string pointed to by | ||
55 | .Fa nptr | ||
56 | to | ||
57 | .Li double | ||
58 | representation. | ||
59 | The | ||
60 | .Fn strtof | ||
61 | function converts the initial portion of the string pointed to by | ||
62 | .Fa nptr | ||
63 | to | ||
64 | .Li float | ||
65 | representation. | ||
66 | .Pp | ||
67 | The expected form of the string is an optional plus | ||
68 | .Pq Ql + | ||
69 | or minus sign | ||
70 | .Pq Ql - | ||
71 | followed by a sequence of digits optionally containing | ||
72 | a decimal-point character, optionally followed by an exponent. | ||
73 | An exponent consists of an | ||
74 | .Sq E | ||
75 | or | ||
76 | .Sq e , | ||
77 | followed by an optional plus or minus sign, followed by a sequence of digits. | ||
78 | .Pp | ||
79 | Leading whitespace characters in the string (as defined by the | ||
80 | .Xr isspace 3 | ||
81 | function) are skipped. | ||
82 | .Sh RETURN VALUES | ||
83 | The | ||
84 | .Fn strtod | ||
85 | and | ||
86 | .Fn strtof | ||
87 | functions return the converted value, if any. | ||
88 | .Pp | ||
89 | If | ||
90 | .Fa endptr | ||
91 | is not | ||
92 | .Dv NULL , | ||
93 | a pointer to the character after the last character used | ||
94 | in the conversion is stored in the location referenced by | ||
95 | .Fa endptr . | ||
96 | .Pp | ||
97 | If no conversion is performed, zero is returned and the value of | ||
98 | .Fa nptr | ||
99 | is stored in the location referenced by | ||
100 | .Fa endptr . | ||
101 | .Pp | ||
102 | If the correct value would cause overflow, plus or minus | ||
103 | .Dv HUGE_VAL | ||
104 | is returned (according to the sign of the value), and | ||
105 | .Er ERANGE | ||
106 | is stored in | ||
107 | .Va errno . | ||
108 | If the correct value would cause underflow, zero is returned and | ||
109 | .Er ERANGE | ||
110 | is stored in | ||
111 | .Va errno . | ||
112 | .Sh ERRORS | ||
113 | .Bl -tag -width Er | ||
114 | .It Bq Er ERANGE | ||
115 | Overflow or underflow occurred. | ||
116 | .El | ||
117 | .Sh SEE ALSO | ||
118 | .Xr atof 3 , | ||
119 | .Xr atoi 3 , | ||
120 | .Xr atol 3 , | ||
121 | .Xr strtol 3 , | ||
122 | .Xr strtoul 3 | ||
123 | .Sh STANDARDS | ||
124 | The | ||
125 | .Fn strtod | ||
126 | and | ||
127 | .Fn strtof | ||
128 | functions conform to | ||
129 | .St -ansiC . | ||