]> git.saurik.com Git - apple/libc.git/blame - stdlib/FreeBSD/strtod.3
Libc-594.9.5.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.
16.\" 3. All advertising materials mentioning features or use of this software
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
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" @(#)strtod.3 8.1 (Berkeley) 6/4/93
3d9156a7 37.\" $FreeBSD: src/lib/libc/stdlib/strtod.3,v 1.19 2003/05/22 13:02:28 ru Exp $
5b2abdfb 38.\"
9385eb3d 39.Dd March 2, 2003
5b2abdfb
A
40.Dt STRTOD 3
41.Os
42.Sh NAME
9385eb3d 43.Nm strtod , strtof , strtold
5b2abdfb
A
44.Nd convert
45.Tn ASCII
9385eb3d 46string to floating point
5b2abdfb
A
47.Sh LIBRARY
48.Lb libc
49.Sh SYNOPSIS
50.In stdlib.h
51.Ft double
9385eb3d
A
52.Fn strtod "const char * restrict nptr" "char ** restrict endptr"
53.Ft float
54.Fn strtof "const char * restrict nptr" "char ** restrict endptr"
3d9156a7 55.Ft "long double"
9385eb3d 56.Fn strtold "const char * restrict nptr" "char ** restrict endptr"
5b2abdfb 57.Sh DESCRIPTION
9385eb3d
A
58These conversion
59functions convert the initial portion of the string
5b2abdfb
A
60pointed to by
61.Fa nptr
62to
9385eb3d
A
63.Vt double ,
64.Vt float ,
65and
3d9156a7 66.Vt "long double"
9385eb3d 67representation, respectively.
5b2abdfb
A
68.Pp
69The expected form of the string is an optional plus (``+'') or minus
9385eb3d
A
70sign (``\-'') followed by either:
71.Bl -bullet
72.It
73a decimal significand consisting of a sequence of decimal digits
74optionally containing a decimal-point character, or
75.It
76a hexadecimal significand consisting of a ``0X'' or ``0x'' followed
77by a sequence of hexadecimal digits optionally containing a
78decimal-point character.
79.El
80.Pp
81In both cases, the significand may be optionally followed by an
82exponent.
83An exponent consists of an ``E'' or ``e'' (for decimal
84constants) or a ``P'' or ``p'' (for hexadecimal constants),
85followed by an optional plus or minus sign, followed by a
86sequence of decimal digits.
87For decimal constants, the exponent indicates the power of 10 by
88which the significand should be scaled.
89For hexadecimal constants, the scaling is instead done by powers
90of 2.
5b2abdfb 91.Pp
9385eb3d
A
92Alternatively, if the portion of the string following the optional
93plus or minus sign begins with ``INFINITY'' or ``NAN'', ignoring
94case, it is interpreted as an infinity or a quiet NaN, respectively.
95.Pp
96In any of the above cases, leading white-space characters in the
97string (as defined by the
5b2abdfb
A
98.Xr isspace 3
99function) are skipped.
100The decimal point
101character is defined in the program's locale (category
102.Dv LC_NUMERIC ) .
103.Sh RETURN VALUES
104The
9385eb3d
A
105.Fn strtod ,
106.Fn strtof ,
107and
108.Fn strtold
109functions return the converted value, if any.
5b2abdfb
A
110.Pp
111If
112.Fa endptr
113is not
114.Dv NULL ,
115a pointer to the character after the last character used
116in the conversion is stored in the location referenced by
117.Fa endptr .
118.Pp
119If no conversion is performed, zero is returned and the value of
120.Fa nptr
121is stored in the location referenced by
122.Fa endptr .
123.Pp
124If the correct value would cause overflow, plus or minus
9385eb3d
A
125.Dv HUGE_VAL ,
126.Dv HUGE_VALF ,
127or
128.Dv HUGE_VALL
129is returned (according to the sign and type of the return value), and
5b2abdfb
A
130.Er ERANGE
131is stored in
132.Va errno .
133If the correct value would cause underflow, zero is
134returned and
135.Er ERANGE
136is stored in
137.Va errno .
138.Sh ERRORS
139.Bl -tag -width Er
140.It Bq Er ERANGE
141Overflow or underflow occurred.
142.El
143.Sh SEE ALSO
144.Xr atof 3 ,
145.Xr atoi 3 ,
146.Xr atol 3 ,
147.Xr strtol 3 ,
9385eb3d
A
148.Xr strtoul 3 ,
149.Xr wcstod 3
5b2abdfb
A
150.Sh STANDARDS
151The
152.Fn strtod
153function
154conforms to
9385eb3d
A
155.St -isoC-99 ,
156with the exception of the bug noted below.
157.Sh BUGS
158These routines do not recognize the C99 ``NaN(...)'' syntax.
5b2abdfb
A
159.Sh AUTHORS
160The author of this software is
161.An David M. Gay .
162.Pp
3d9156a7 163.Bd -literal
9385eb3d 164Copyright (c) 1998 by Lucent Technologies
9385eb3d 165All Rights Reserved
3d9156a7 166
9385eb3d
A
167Permission to use, copy, modify, and distribute this software and
168its documentation for any purpose and without fee is hereby
169granted, provided that the above copyright notice appear in all
170copies and that both that the copyright notice and this
171permission notice and warranty disclaimer appear in supporting
172documentation, and that the name of Lucent or any of its entities
173not be used in advertising or publicity pertaining to
174distribution of the software without specific, written prior
175permission.
3d9156a7 176
9385eb3d
A
177LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
178INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
179IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
180SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
181WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
182IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
183ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
184THIS SOFTWARE.
3d9156a7 185.Ed