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