summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/strtod.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/strtod.3')
-rw-r--r--src/lib/libc/stdlib/strtod.3170
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
43string 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
56The
57.Fn strtod
58function converts the initial portion of the string pointed to by
59.Fa nptr
60to
61.Li double
62representation.
63The
64.Fn strtof
65function converts the initial portion of the string pointed to by
66.Fa nptr
67to
68.Li float
69representation.
70The
71.Fn strtold
72function converts the initial portion of the string pointed to by
73.Fa nptr
74to
75.Li long double
76representation.
77.Pp
78The expected form of the string is an optional plus
79.Pq Ql +
80or minus sign
81.Pq Ql -
82followed by a sequence of digits optionally containing
83a decimal-point character, optionally followed by an exponent.
84An exponent consists of an
85.Sq E
86or
87.Sq e ,
88followed by an optional plus or minus sign, followed by a sequence of digits.
89.Pp
90Alternatively, if the portion of the string following the optional
91plus or minus sign begins with
92.Dq INF
93or
94.Dq NAN ,
95ignoring case, it is interpreted as an infinity or a quiet \*(Na,
96respectively.
97The syntax
98.Dq NAN Ns Pq Ar s ,
99where
100.Ar s
101is 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
109and
110.Fo nanl
111.Qq Ar s Ns
112.Fc . )
113.Pp
114In any of the above cases, leading whitespace characters in the
115string (as defined by the
116.Xr isspace 3
117function) are skipped.
118.Sh RETURN VALUES
119The
120.Fn strtod ,
121.Fn strtof
122and
123.Fn strtold
124functions return the converted value, if any.
125.Pp
126If
127.Fa endptr
128is not
129.Dv NULL ,
130a pointer to the character after the last character used
131in the conversion is stored in the location referenced by
132.Fa endptr .
133.Pp
134If no conversion is performed, zero is returned and the value of
135.Fa nptr
136is stored in the location referenced by
137.Fa endptr .
138.Pp
139If the correct value would cause overflow, plus or minus
140.Dv HUGE_VAL
141is returned (according to the sign of the value), and
142.Er ERANGE
143is stored in
144.Va errno .
145If the correct value would cause underflow, zero is returned and
146.Er ERANGE
147is stored in
148.Va errno .
149.Sh ERRORS
150.Bl -tag -width Er
151.It Bq Er ERANGE
152Overflow 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
161The
162.Fn strtod
163function conforms to
164.St -ansiC-89 .
165The
166.Fn strtof
167and
168.Fn strtold
169functions conform to
170.St -ansiC-99 .