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