diff options
Diffstat (limited to 'src/lib/libc/stdlib/strtod.3')
-rw-r--r-- | src/lib/libc/stdlib/strtod.3 | 170 |
1 files changed, 170 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..0066cc02f3 --- /dev/null +++ b/src/lib/libc/stdlib/strtod.3 | |||
@@ -0,0 +1,170 @@ | |||
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.16 2012/09/16 17:54:03 jmc Exp $ | ||
33 | .\" | ||
34 | .Dd $Mdocdate: September 16 2012 $ | ||
35 | .Dt STRTOD 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm strtod , | ||
39 | .Nm strtof , | ||
40 | .Nm strtold | ||
41 | .Nd convert | ||
42 | .Tn ASCII | ||
43 | string to double, float or long double | ||
44 | .Sh SYNOPSIS | ||
45 | .Fd #include <math.h> | ||
46 | .Fd #include <stdlib.h> | ||
47 | .Ft double | ||
48 | .Fn strtod "const char *nptr" "char **endptr" | ||
49 | .Pp | ||
50 | .Ft float | ||
51 | .Fn strtof "const char *nptr" "char **endptr" | ||
52 | .Pp | ||
53 | .Ft long double | ||
54 | .Fn strtold "const char *nptr" "char **endptr" | ||
55 | .Sh DESCRIPTION | ||
56 | The | ||
57 | .Fn strtod | ||
58 | function converts the initial portion of the string pointed to by | ||
59 | .Fa nptr | ||
60 | to | ||
61 | .Li double | ||
62 | representation. | ||
63 | The | ||
64 | .Fn strtof | ||
65 | function converts the initial portion of the string pointed to by | ||
66 | .Fa nptr | ||
67 | to | ||
68 | .Li float | ||
69 | representation. | ||
70 | The | ||
71 | .Fn strtold | ||
72 | function converts the initial portion of the string pointed to by | ||
73 | .Fa nptr | ||
74 | to | ||
75 | .Li long double | ||
76 | representation. | ||
77 | .Pp | ||
78 | The expected form of the string is an optional plus | ||
79 | .Pq Ql + | ||
80 | or minus sign | ||
81 | .Pq Ql - | ||
82 | followed by a sequence of digits optionally containing | ||
83 | a decimal-point character, optionally followed by an exponent. | ||
84 | An exponent consists of an | ||
85 | .Sq E | ||
86 | or | ||
87 | .Sq e , | ||
88 | followed by an optional plus or minus sign, followed by a sequence of digits. | ||
89 | .Pp | ||
90 | Alternatively, if the portion of the string following the optional | ||
91 | plus or minus sign begins with | ||
92 | .Dq INF | ||
93 | or | ||
94 | .Dq NAN , | ||
95 | ignoring case, it is interpreted as an infinity or a quiet \*(Na, | ||
96 | respectively. | ||
97 | The syntax | ||
98 | .Dq NAN Ns Pq Ar s , | ||
99 | where | ||
100 | .Ar s | ||
101 | is an alphanumeric string, produces the same value as the call | ||
102 | .Fo nan | ||
103 | .Qq Ar s Ns | ||
104 | .Fc | ||
105 | (respectively, | ||
106 | .Fo nanf | ||
107 | .Qq Ar s Ns | ||
108 | .Fc | ||
109 | and | ||
110 | .Fo nanl | ||
111 | .Qq Ar s Ns | ||
112 | .Fc . ) | ||
113 | .Pp | ||
114 | In any of the above cases, leading whitespace characters in the | ||
115 | string (as defined by the | ||
116 | .Xr isspace 3 | ||
117 | function) are skipped. | ||
118 | .Sh RETURN VALUES | ||
119 | The | ||
120 | .Fn strtod , | ||
121 | .Fn strtof | ||
122 | and | ||
123 | .Fn strtold | ||
124 | functions return the converted value, if any. | ||
125 | .Pp | ||
126 | If | ||
127 | .Fa endptr | ||
128 | is not | ||
129 | .Dv NULL , | ||
130 | a pointer to the character after the last character used | ||
131 | in the conversion is stored in the location referenced by | ||
132 | .Fa endptr . | ||
133 | .Pp | ||
134 | If no conversion is performed, zero is returned and the value of | ||
135 | .Fa nptr | ||
136 | is stored in the location referenced by | ||
137 | .Fa endptr . | ||
138 | .Pp | ||
139 | If the correct value would cause overflow, plus or minus | ||
140 | .Dv HUGE_VAL | ||
141 | is returned (according to the sign of the value), and | ||
142 | .Er ERANGE | ||
143 | is stored in | ||
144 | .Va errno . | ||
145 | If the correct value would cause underflow, zero is returned and | ||
146 | .Er ERANGE | ||
147 | is stored in | ||
148 | .Va errno . | ||
149 | .Sh ERRORS | ||
150 | .Bl -tag -width Er | ||
151 | .It Bq Er ERANGE | ||
152 | Overflow or underflow occurred. | ||
153 | .El | ||
154 | .Sh SEE ALSO | ||
155 | .Xr atof 3 , | ||
156 | .Xr atoi 3 , | ||
157 | .Xr atol 3 , | ||
158 | .Xr strtol 3 , | ||
159 | .Xr strtoul 3 | ||
160 | .Sh STANDARDS | ||
161 | The | ||
162 | .Fn strtod | ||
163 | function conforms to | ||
164 | .St -ansiC-89 . | ||
165 | The | ||
166 | .Fn strtof | ||
167 | and | ||
168 | .Fn strtold | ||
169 | functions conform to | ||
170 | .St -ansiC-99 . | ||