]> git.saurik.com Git - apple/libc.git/blame - stdlib/FreeBSD/strtod.3
Libc-1044.1.2.tar.gz
[apple/libc.git] / stdlib / FreeBSD / strtod.3
CommitLineData
5b2abdfb
A
1.\" Copyright (c) 1990, 1991, 1993
2.\" The Regents of the University of California. 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.
5b2abdfb
A
16.\" 4. 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.\" @(#)strtod.3 8.1 (Berkeley) 6/4/93
1f2f436a 33.\" $FreeBSD: src/lib/libc/stdlib/strtod.3,v 1.22 2007/12/16 21:19:28 das Exp $
5b2abdfb 34.\"
9385eb3d 35.Dd March 2, 2003
5b2abdfb
A
36.Dt STRTOD 3
37.Os
38.Sh NAME
9385eb3d 39.Nm strtod , strtof , strtold
5b2abdfb
A
40.Nd convert
41.Tn ASCII
9385eb3d 42string to floating point
5b2abdfb
A
43.Sh LIBRARY
44.Lb libc
45.Sh SYNOPSIS
46.In stdlib.h
47.Ft double
ad3c9f2a
A
48.Fo strtod
49.Fa "const char *restrict nptr"
50.Fa "char **restrict endptr"
51.Fc
9385eb3d 52.Ft float
ad3c9f2a
A
53.Fo strtof
54.Fa "const char *restrict nptr"
55.Fa "char **restrict endptr"
56.Fc
3d9156a7 57.Ft "long double"
ad3c9f2a
A
58.Fo strtold
59.Fa "const char *restrict nptr"
60.Fa "char **restrict endptr"
61.Fc
5b2abdfb 62.Sh DESCRIPTION
9385eb3d
A
63These conversion
64functions convert the initial portion of the string
5b2abdfb
A
65pointed to by
66.Fa nptr
67to
9385eb3d
A
68.Vt double ,
69.Vt float ,
70and
3d9156a7 71.Vt "long double"
9385eb3d 72representation, respectively.
5b2abdfb 73.Pp
ad3c9f2a
A
74The expected form of the string
75is an optional plus (``+'') or minus (``\-'') sign,
76followed by either:
9385eb3d
A
77.Bl -bullet
78.It
ad3c9f2a
A
79a decimal significand, consisting of a sequence of decimal digits
80(optionally containing a decimal-point character) or
9385eb3d 81.It
ad3c9f2a
A
82a hexadecimal significand, consisting of a ``0X'' or ``0x'' followed
83by a sequence of hexadecimal digits
84(optionally containing a decimal-point character).
9385eb3d
A
85.El
86.Pp
87In both cases, the significand may be optionally followed by an
88exponent.
89An exponent consists of an ``E'' or ``e'' (for decimal
90constants) or a ``P'' or ``p'' (for hexadecimal constants),
91followed by an optional plus or minus sign, followed by a
92sequence of decimal digits.
93For decimal constants, the exponent indicates the power of 10 by
94which the significand should be scaled.
95For hexadecimal constants, the scaling is instead done by powers
96of 2.
5b2abdfb 97.Pp
9385eb3d 98Alternatively, if the portion of the string following the optional
1f2f436a
A
99plus or minus sign begins with
100.Dq INFINITY
101or
102.Dq NAN ,
103ignoring case, it is interpreted as an infinity or a quiet \*(Na,
104respectively.
105The syntax
106.Dq Xo Pf NAN( Ar "s" ) Xc ,
107where
108.Ar s
109is an alphanumeric string, produces the same value as the call
110.Fo nan
111.Qq Ar s Ns
112.Fc
113(respectively,
114.Fo nanf
115.Qq Ar s Ns
116.Fc
117and
118.Fo nanl
119.Qq Ar s Ns
120.Fc . )
9385eb3d
A
121.Pp
122In any of the above cases, leading white-space characters in the
123string (as defined by the
5b2abdfb
A
124.Xr isspace 3
125function) are skipped.
126The decimal point
127character is defined in the program's locale (category
128.Dv LC_NUMERIC ) .
ad3c9f2a
A
129.Pp
130Extended locale versions of these functions are documented in
131.Xr strtod_l 3 .
132See
133.Xr xlocale 3
134for more information.
5b2abdfb
A
135.Sh RETURN VALUES
136The
9385eb3d
A
137.Fn strtod ,
138.Fn strtof ,
139and
140.Fn strtold
141functions return the converted value, if any.
5b2abdfb
A
142.Pp
143If
144.Fa endptr
145is not
146.Dv NULL ,
147a pointer to the character after the last character used
148in the conversion is stored in the location referenced by
149.Fa endptr .
150.Pp
151If no conversion is performed, zero is returned and the value of
152.Fa nptr
153is stored in the location referenced by
154.Fa endptr .
155.Pp
156If the correct value would cause overflow, plus or minus
9385eb3d
A
157.Dv HUGE_VAL ,
158.Dv HUGE_VALF ,
159or
160.Dv HUGE_VALL
161is returned (according to the sign and type of the return value), and
5b2abdfb
A
162.Er ERANGE
163is stored in
164.Va errno .
165If the correct value would cause underflow, zero is
166returned and
167.Er ERANGE
168is stored in
169.Va errno .
170.Sh ERRORS
171.Bl -tag -width Er
172.It Bq Er ERANGE
173Overflow or underflow occurred.
174.El
175.Sh SEE ALSO
176.Xr atof 3 ,
177.Xr atoi 3 ,
178.Xr atol 3 ,
1f2f436a 179.Xr nan 3 ,
ad3c9f2a 180.Xr strtod_l 3 ,
5b2abdfb 181.Xr strtol 3 ,
9385eb3d
A
182.Xr strtoul 3 ,
183.Xr wcstod 3
5b2abdfb
A
184.Sh STANDARDS
185The
186.Fn strtod
187function
188conforms to
ad3c9f2a 189.St -isoC-99 .
5b2abdfb
A
190.Sh AUTHORS
191The author of this software is
192.An David M. Gay .
193.Pp
3d9156a7 194.Bd -literal
9385eb3d 195Copyright (c) 1998 by Lucent Technologies
9385eb3d 196All Rights Reserved
3d9156a7 197
9385eb3d
A
198Permission to use, copy, modify, and distribute this software and
199its documentation for any purpose and without fee is hereby
200granted, provided that the above copyright notice appear in all
201copies and that both that the copyright notice and this
202permission notice and warranty disclaimer appear in supporting
203documentation, and that the name of Lucent or any of its entities
204not be used in advertising or publicity pertaining to
205distribution of the software without specific, written prior
206permission.
3d9156a7 207
9385eb3d
A
208LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
209INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
210IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
211SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
212WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
213IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
214ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
215THIS SOFTWARE.
3d9156a7 216.Ed