xref: /netbsd-src/lib/libc/stdlib/strtod.3 (revision 5e4c038a45edbc7d63b7c2daa76e29f88b64a4e3)
1.\"	$NetBSD: strtod.3,v 1.13 2002/02/07 07:00:30 ross Exp $
2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" the American National Standards Committee X3, on Information
8.\" Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. All advertising materials mentioning features or use of this software
19.\"    must display the following acknowledgement:
20.\"	This product includes software developed by the University of
21.\"	California, Berkeley and its contributors.
22.\" 4. Neither the name of the University nor the names of its contributors
23.\"    may be used to endorse or promote products derived from this software
24.\"    without specific prior written permission.
25.\"
26.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36.\" SUCH DAMAGE.
37.\"
38.\"     from: @(#)strtod.3	8.1 (Berkeley) 6/4/93
39.\"
40.Dd January 28, 2002
41.Dt STRTOD 3
42.Os
43.Sh NAME
44.Nm strtod
45.Nd convert
46.Tn ASCII
47string to double
48.Sh LIBRARY
49.Lb libc
50.Sh SYNOPSIS
51.Fd #include \*[Lt]stdlib.h\*[Gt]
52.Ft double
53.Fn strtod "const char * restrict nptr" "char ** restrict endptr"
54.Sh DESCRIPTION
55The
56.Fn strtod
57function converts the initial portion of the string
58pointed to by
59.Fa nptr
60to
61.Em double
62representation.
63.Pp
64The expected form of the string is an optional plus (``+'') or minus
65sign (``\-'') followed by one of the following:
66.Bl -dash
67.It
68a sequence of digits optionally containing
69a decimal-point character, optionally followed by an exponent.
70An exponent consists of an ``E'' or ``e'', followed by an optional plus
71or minus sign, followed by a sequence of digits.
72.It
73one of
74.Li INF
75or
76.Li INFINITY ,
77ignoring case.
78.It
79one of
80.Li NAN
81or
82.Li NAN(n-char-sequence-opt) ,
83ignoring case.
84This implementation currently does not interpret such a sequence.
85.El
86.Pp
87Leading white-space characters in the string (as defined by the
88.Xr isspace 3
89function) are skipped.
90.Sh RETURN VALUES
91The
92.Fn strtod
93function returns the converted value, if any.
94.Pp
95A character sequence
96.Li INF
97or
98.Li INFINITY
99is converted to \*(If,
100if supported, else to the largest finite floating-point number representable
101on the machine (i.e.,
102.Tn VAX ) .
103.Pp
104A character sequence
105.Li NAN
106or
107.Li NAN(n-char-sequence-opt)
108is converted to a quiet \*(Na, if supported, else to a
109.Dq reserved operand
110for that machine (i.e.,
111.Tn VAX ) .
112.Pp
113If
114.Fa endptr
115is not
116.Dv NULL ,
117a pointer to the character after the last character used
118in the conversion is stored in the location referenced by
119.Fa endptr .
120.Pp
121If no conversion is performed, zero is returned and the value of
122.Fa nptr
123is stored in the location referenced by
124.Fa endptr .
125.Pp
126If the correct value would cause overflow, plus or minus
127.Dv HUGE_VAL
128is returned (according to the sign of the value), and
129.Dv ERANGE
130is stored in
131.Va errno .
132If the correct value would cause underflow, zero is
133returned and
134.Dv ERANGE
135is stored in
136.Va errno .
137.Sh ERRORS
138.Bl -tag -width Er
139.It Bq Er ERANGE
140Overflow or underflow occurred.
141.El
142.Sh SEE ALSO
143.Xr atof 3 ,
144.Xr atoi 3 ,
145.Xr atol 3 ,
146.Xr math 3 ,
147.Xr strtol 3 ,
148.Xr strtoul 3
149.Sh STANDARDS
150The
151.Fn strtod
152function
153conforms to
154.St -ansiC .
155