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