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.3115
1 files changed, 84 insertions, 31 deletions
diff --git a/src/lib/libc/stdlib/strtod.3 b/src/lib/libc/stdlib/strtod.3
index 0b7f973857..6f079b73a9 100644
--- a/src/lib/libc/stdlib/strtod.3
+++ b/src/lib/libc/stdlib/strtod.3
@@ -13,11 +13,7 @@
13.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the 14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution. 15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software 16.\" 3. Neither the name of the University nor the names of its contributors
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software 17.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission. 18.\" without specific prior written permission.
23.\" 19.\"
@@ -33,44 +29,96 @@
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE. 30.\" SUCH DAMAGE.
35.\" 31.\"
36.\" from: @(#)strtod.3 5.3 (Berkeley) 6/29/91 32.\" $OpenBSD: strtod.3,v 1.19 2014/01/19 10:39:00 schwarze Exp $
37.\" $Id: strtod.3,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $
38.\" 33.\"
39.Dd June 29, 1991 34.Dd $Mdocdate: January 19 2014 $
40.Dt STRTOD 3 35.Dt STRTOD 3
41.Os 36.Os
42.Sh NAME 37.Sh NAME
43.Nm strtod 38.Nm strtod ,
44.Nd convert 39.Nm strtof ,
45.Tn ASCII 40.Nm strtold
46string to double 41.Nd convert ASCII string to double, float or long double
47.Sh SYNOPSIS 42.Sh SYNOPSIS
48.Fd #include <stdlib.h> 43.In stdlib.h
49.Ft double 44.Ft double
50.Fn strtod "const char *nptr" "char **endptr" 45.Fn strtod "const char *nptr" "char **endptr"
46.Pp
47.Ft float
48.Fn strtof "const char *nptr" "char **endptr"
49.Pp
50.Ft long double
51.Fn strtold "const char *nptr" "char **endptr"
51.Sh DESCRIPTION 52.Sh DESCRIPTION
52The 53The
53.Fn strtod 54.Fn strtod
54function converts the initial portion of the string 55function converts the initial portion of the string pointed to by
55pointed to by 56.Fa nptr
57to
58.Li double
59representation.
60The
61.Fn strtof
62function converts the initial portion of the string pointed to by
63.Fa nptr
64to
65.Li float
66representation.
67The
68.Fn strtold
69function converts the initial portion of the string pointed to by
56.Fa nptr 70.Fa nptr
57to 71to
58.Em double 72.Li long double
59representation. 73representation.
60.Pp 74.Pp
61The expected form of the string is an optional plus (``+'') or minus 75The expected form of the string is an optional plus
62sign (``-'') followed by a sequence of digits optionally containing 76.Pq Ql +
77or minus sign
78.Pq Ql -
79followed by a sequence of digits optionally containing
63a decimal-point character, optionally followed by an exponent. 80a decimal-point character, optionally followed by an exponent.
64An exponent consists of an ``E'' or ``e'', followed by an optional plus 81An exponent consists of an
65or minus sign, followed by a sequence of digits. 82.Sq E
83or
84.Sq e ,
85followed by an optional plus or minus sign, followed by a sequence of digits.
86.Pp
87Alternatively, if the portion of the string following the optional
88plus or minus sign begins with
89.Dq INF
90or
91.Dq NAN ,
92ignoring case, it is interpreted as an infinity or a quiet \*(Na,
93respectively.
94The syntax
95.Dq NAN Ns Pq Ar s ,
96where
97.Ar s
98is an alphanumeric string, produces the same value as the call
99.Fo nan
100.Qq Ar s Ns
101.Fc
102(respectively,
103.Fo nanf
104.Qq Ar s Ns
105.Fc
106and
107.Fo nanl
108.Qq Ar s Ns
109.Fc . )
66.Pp 110.Pp
67Leading white-space characters in the string (as defined by the 111In any of the above cases, leading whitespace characters in the
112string (as defined by the
68.Xr isspace 3 113.Xr isspace 3
69function) are skipped. 114function) are skipped.
70.Sh RETURN VALUES 115.Sh RETURN VALUES
71The 116The
72.Fn strtod 117.Fn strtod ,
73function returns the converted value, if any. 118.Fn strtof
119and
120.Fn strtold
121functions return the converted value, if any.
74.Pp 122.Pp
75If 123If
76.Fa endptr 124.Fa endptr
@@ -88,18 +136,18 @@ is stored in the location referenced by
88If the correct value would cause overflow, plus or minus 136If the correct value would cause overflow, plus or minus
89.Dv HUGE_VAL 137.Dv HUGE_VAL
90is returned (according to the sign of the value), and 138is returned (according to the sign of the value), and
91.Dv ERANGE 139.Er ERANGE
92is stored in 140is stored in
93.Va errno . 141.Va errno .
94If the correct value would cause underflow, zero is 142If the correct value would cause underflow, zero is returned and
95returned and 143.Er ERANGE
96.Dv ERANGE 144is stored in
97is stored in
98.Va errno . 145.Va errno .
99.Sh ERRORS 146.Sh ERRORS
100.Bl -tag -width Er 147.Bl -tag -width Er
101.It Bq Er ERANGE 148.It Bq Er ERANGE
102Overflow or underflow occurred. 149Overflow or underflow occurred.
150.El
103.Sh SEE ALSO 151.Sh SEE ALSO
104.Xr atof 3 , 152.Xr atof 3 ,
105.Xr atoi 3 , 153.Xr atoi 3 ,
@@ -109,6 +157,11 @@ Overflow or underflow occurred.
109.Sh STANDARDS 157.Sh STANDARDS
110The 158The
111.Fn strtod 159.Fn strtod
112function 160function conforms to
113conforms to 161.St -ansiC-89 .
114.St -ansiC . 162The
163.Fn strtof
164and
165.Fn strtold
166functions conform to
167.St -ansiC-99 .