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.3112
1 files changed, 84 insertions, 28 deletions
diff --git a/src/lib/libc/stdlib/strtod.3 b/src/lib/libc/stdlib/strtod.3
index 0b7f973857..0066cc02f3 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,99 @@
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.16 2012/09/16 17:54:03 jmc 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: September 16 2012 $
40.Dt STRTOD 3 35.Dt STRTOD 3
41.Os 36.Os
42.Sh NAME 37.Sh NAME
43.Nm strtod 38.Nm strtod ,
39.Nm strtof ,
40.Nm strtold
44.Nd convert 41.Nd convert
45.Tn ASCII 42.Tn ASCII
46string to double 43string to double, float or long double
47.Sh SYNOPSIS 44.Sh SYNOPSIS
45.Fd #include <math.h>
48.Fd #include <stdlib.h> 46.Fd #include <stdlib.h>
49.Ft double 47.Ft double
50.Fn strtod "const char *nptr" "char **endptr" 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"
51.Sh DESCRIPTION 55.Sh DESCRIPTION
52The 56The
53.Fn strtod 57.Fn strtod
54function converts the initial portion of the string 58function converts the initial portion of the string pointed to by
55pointed 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
56.Fa nptr 73.Fa nptr
57to 74to
58.Em double 75.Li long double
59representation. 76representation.
60.Pp 77.Pp
61The expected form of the string is an optional plus (``+'') or minus 78The expected form of the string is an optional plus
62sign (``-'') followed by a sequence of digits optionally containing 79.Pq Ql +
80or minus sign
81.Pq Ql -
82followed by a sequence of digits optionally containing
63a decimal-point character, optionally followed by an exponent. 83a decimal-point character, optionally followed by an exponent.
64An exponent consists of an ``E'' or ``e'', followed by an optional plus 84An exponent consists of an
65or minus sign, followed by a sequence of digits. 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 . )
66.Pp 113.Pp
67Leading white-space characters in the string (as defined by the 114In any of the above cases, leading whitespace characters in the
115string (as defined by the
68.Xr isspace 3 116.Xr isspace 3
69function) are skipped. 117function) are skipped.
70.Sh RETURN VALUES 118.Sh RETURN VALUES
71The 119The
72.Fn strtod 120.Fn strtod ,
73function returns the converted value, if any. 121.Fn strtof
122and
123.Fn strtold
124functions return the converted value, if any.
74.Pp 125.Pp
75If 126If
76.Fa endptr 127.Fa endptr
@@ -88,18 +139,18 @@ is stored in the location referenced by
88If the correct value would cause overflow, plus or minus 139If the correct value would cause overflow, plus or minus
89.Dv HUGE_VAL 140.Dv HUGE_VAL
90is returned (according to the sign of the value), and 141is returned (according to the sign of the value), and
91.Dv ERANGE 142.Er ERANGE
92is stored in 143is stored in
93.Va errno . 144.Va errno .
94If the correct value would cause underflow, zero is 145If the correct value would cause underflow, zero is returned and
95returned and 146.Er ERANGE
96.Dv ERANGE 147is stored in
97is stored in
98.Va errno . 148.Va errno .
99.Sh ERRORS 149.Sh ERRORS
100.Bl -tag -width Er 150.Bl -tag -width Er
101.It Bq Er ERANGE 151.It Bq Er ERANGE
102Overflow or underflow occurred. 152Overflow or underflow occurred.
153.El
103.Sh SEE ALSO 154.Sh SEE ALSO
104.Xr atof 3 , 155.Xr atof 3 ,
105.Xr atoi 3 , 156.Xr atoi 3 ,
@@ -109,6 +160,11 @@ Overflow or underflow occurred.
109.Sh STANDARDS 160.Sh STANDARDS
110The 161The
111.Fn strtod 162.Fn strtod
112function 163function conforms to
113conforms to 164.St -ansiC-89 .
114.St -ansiC . 165The
166.Fn strtof
167and
168.Fn strtold
169functions conform to
170.St -ansiC-99 .