158f0484fSRodney W. Grimes.\" Copyright (c) 1990, 1991, 1993 258f0484fSRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 358f0484fSRodney W. Grimes.\" 458f0484fSRodney W. Grimes.\" This code is derived from software contributed to Berkeley by 558f0484fSRodney W. Grimes.\" the American National Standards Committee X3, on Information 658f0484fSRodney W. Grimes.\" Processing Systems. 758f0484fSRodney W. Grimes.\" 858f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 958f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions 1058f0484fSRodney W. Grimes.\" are met: 1158f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 1258f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 1358f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 1458f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 1558f0484fSRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 1658f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 1758f0484fSRodney W. Grimes.\" may be used to endorse or promote products derived from this software 1858f0484fSRodney W. Grimes.\" without specific prior written permission. 1958f0484fSRodney W. Grimes.\" 2058f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2158f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2258f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2358f0484fSRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2458f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2558f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2658f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2758f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2858f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2958f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3058f0484fSRodney W. Grimes.\" SUCH DAMAGE. 3158f0484fSRodney W. Grimes.\" 3258f0484fSRodney W. Grimes.\" @(#)strtod.3 8.1 (Berkeley) 6/4/93 337f3dea24SPeter Wemm.\" $FreeBSD$ 3458f0484fSRodney W. Grimes.\" 35*e91cb7f0SChristian Brueffer.Dd May 11, 2010 3658f0484fSRodney W. Grimes.Dt STRTOD 3 3758f0484fSRodney W. Grimes.Os 3858f0484fSRodney W. Grimes.Sh NAME 39703d6560SDavid Schultz.Nm strtod , strtof , strtold 4058f0484fSRodney W. Grimes.Nd convert 4158f0484fSRodney W. Grimes.Tn ASCII 42703d6560SDavid Schultzstring to floating point 4325bb73e0SAlexey Zelkin.Sh LIBRARY 4425bb73e0SAlexey Zelkin.Lb libc 4558f0484fSRodney W. Grimes.Sh SYNOPSIS 468aefde06SJeroen Ruigrok van der Werven.In stdlib.h 4758f0484fSRodney W. Grimes.Ft double 485618f724SRobert Drehmel.Fn strtod "const char * restrict nptr" "char ** restrict endptr" 49703d6560SDavid Schultz.Ft float 50703d6560SDavid Schultz.Fn strtof "const char * restrict nptr" "char ** restrict endptr" 513a5146d9SRuslan Ermilov.Ft "long double" 52703d6560SDavid Schultz.Fn strtold "const char * restrict nptr" "char ** restrict endptr" 5358f0484fSRodney W. Grimes.Sh DESCRIPTION 54703d6560SDavid SchultzThese conversion 55703d6560SDavid Schultzfunctions convert the initial portion of the string 5658f0484fSRodney W. Grimespointed to by 5758f0484fSRodney W. Grimes.Fa nptr 5858f0484fSRodney W. Grimesto 59703d6560SDavid Schultz.Vt double , 60703d6560SDavid Schultz.Vt float , 61703d6560SDavid Schultzand 623a5146d9SRuslan Ermilov.Vt "long double" 63703d6560SDavid Schultzrepresentation, respectively. 6458f0484fSRodney W. Grimes.Pp 6558f0484fSRodney W. GrimesThe expected form of the string is an optional plus (``+'') or minus 66703d6560SDavid Schultzsign (``\-'') followed by either: 67703d6560SDavid Schultz.Bl -bullet 68703d6560SDavid Schultz.It 69703d6560SDavid Schultza decimal significand consisting of a sequence of decimal digits 70703d6560SDavid Schultzoptionally containing a decimal-point character, or 71703d6560SDavid Schultz.It 72703d6560SDavid Schultza hexadecimal significand consisting of a ``0X'' or ``0x'' followed 73703d6560SDavid Schultzby a sequence of hexadecimal digits optionally containing a 74703d6560SDavid Schultzdecimal-point character. 75703d6560SDavid Schultz.El 7658f0484fSRodney W. Grimes.Pp 77703d6560SDavid SchultzIn both cases, the significand may be optionally followed by an 78703d6560SDavid Schultzexponent. 79703d6560SDavid SchultzAn exponent consists of an ``E'' or ``e'' (for decimal 80703d6560SDavid Schultzconstants) or a ``P'' or ``p'' (for hexadecimal constants), 81703d6560SDavid Schultzfollowed by an optional plus or minus sign, followed by a 82703d6560SDavid Schultzsequence of decimal digits. 83703d6560SDavid SchultzFor decimal constants, the exponent indicates the power of 10 by 84703d6560SDavid Schultzwhich the significand should be scaled. 85703d6560SDavid SchultzFor hexadecimal constants, the scaling is instead done by powers 86703d6560SDavid Schultzof 2. 87703d6560SDavid Schultz.Pp 88703d6560SDavid SchultzAlternatively, if the portion of the string following the optional 894b6b5744SDavid Schultzplus or minus sign begins with 904b6b5744SDavid Schultz.Dq INFINITY 914b6b5744SDavid Schultzor 924b6b5744SDavid Schultz.Dq NAN , 934b6b5744SDavid Schultzignoring case, it is interpreted as an infinity or a quiet \*(Na, 944b6b5744SDavid Schultzrespectively. 954b6b5744SDavid SchultzThe syntax 964b6b5744SDavid Schultz.Dq Xo Pf NAN( Ar "s" ) Xc , 974b6b5744SDavid Schultzwhere 984b6b5744SDavid Schultz.Ar s 994b6b5744SDavid Schultzis an alphanumeric string, produces the same value as the call 1004b6b5744SDavid Schultz.Fo nan 1014b6b5744SDavid Schultz.Qq Ar s Ns 1024b6b5744SDavid Schultz.Fc 1034b6b5744SDavid Schultz(respectively, 1044b6b5744SDavid Schultz.Fo nanf 1054b6b5744SDavid Schultz.Qq Ar s Ns 1064b6b5744SDavid Schultz.Fc 1074b6b5744SDavid Schultzand 1084b6b5744SDavid Schultz.Fo nanl 1094b6b5744SDavid Schultz.Qq Ar s Ns 1104b6b5744SDavid Schultz.Fc . ) 111703d6560SDavid Schultz.Pp 112703d6560SDavid SchultzIn any of the above cases, leading white-space characters in the 113703d6560SDavid Schultzstring (as defined by the 11458f0484fSRodney W. Grimes.Xr isspace 3 11558f0484fSRodney W. Grimesfunction) are skipped. 11605a6e1e5SAndrey A. ChernovThe decimal point 117429d919cSRuslan Ermilovcharacter is defined in the program's locale (category 118429d919cSRuslan Ermilov.Dv LC_NUMERIC ) . 11958f0484fSRodney W. Grimes.Sh RETURN VALUES 12058f0484fSRodney W. GrimesThe 121703d6560SDavid Schultz.Fn strtod , 122703d6560SDavid Schultz.Fn strtof , 123703d6560SDavid Schultzand 124703d6560SDavid Schultz.Fn strtold 125703d6560SDavid Schultzfunctions return the converted value, if any. 12658f0484fSRodney W. Grimes.Pp 12758f0484fSRodney W. GrimesIf 12858f0484fSRodney W. Grimes.Fa endptr 12958f0484fSRodney W. Grimesis not 13058f0484fSRodney W. Grimes.Dv NULL , 13158f0484fSRodney W. Grimesa pointer to the character after the last character used 13258f0484fSRodney W. Grimesin the conversion is stored in the location referenced by 13358f0484fSRodney W. Grimes.Fa endptr . 13458f0484fSRodney W. Grimes.Pp 13558f0484fSRodney W. GrimesIf no conversion is performed, zero is returned and the value of 13658f0484fSRodney W. Grimes.Fa nptr 13758f0484fSRodney W. Grimesis stored in the location referenced by 13858f0484fSRodney W. Grimes.Fa endptr . 13958f0484fSRodney W. Grimes.Pp 14058f0484fSRodney W. GrimesIf the correct value would cause overflow, plus or minus 141703d6560SDavid Schultz.Dv HUGE_VAL , 142703d6560SDavid Schultz.Dv HUGE_VALF , 143703d6560SDavid Schultzor 144703d6560SDavid Schultz.Dv HUGE_VALL 145703d6560SDavid Schultzis returned (according to the sign and type of the return value), and 146c23155a4SRuslan Ermilov.Er ERANGE 14758f0484fSRodney W. Grimesis stored in 14858f0484fSRodney W. Grimes.Va errno . 14958f0484fSRodney W. GrimesIf the correct value would cause underflow, zero is 15058f0484fSRodney W. Grimesreturned and 151c23155a4SRuslan Ermilov.Er ERANGE 15258f0484fSRodney W. Grimesis stored in 15358f0484fSRodney W. Grimes.Va errno . 15458f0484fSRodney W. Grimes.Sh ERRORS 155274b6244SAlexey Zelkin.Bl -tag -width Er 15658f0484fSRodney W. Grimes.It Bq Er ERANGE 15758f0484fSRodney W. GrimesOverflow or underflow occurred. 15842635956SRuslan Ermilov.El 15958f0484fSRodney W. Grimes.Sh SEE ALSO 16058f0484fSRodney W. Grimes.Xr atof 3 , 16158f0484fSRodney W. Grimes.Xr atoi 3 , 16258f0484fSRodney W. Grimes.Xr atol 3 , 1634b6b5744SDavid Schultz.Xr nan 3 , 16458f0484fSRodney W. Grimes.Xr strtol 3 , 165ecab372bSTim J. Robbins.Xr strtoul 3 , 166ecab372bSTim J. Robbins.Xr wcstod 3 16758f0484fSRodney W. Grimes.Sh STANDARDS 16858f0484fSRodney W. GrimesThe 16958f0484fSRodney W. Grimes.Fn strtod 17058f0484fSRodney W. Grimesfunction 17158f0484fSRodney W. Grimesconforms to 172*e91cb7f0SChristian Brueffer.St -isoC-99 . 17358f0484fSRodney W. Grimes.Sh AUTHORS 174a5941fc2SPhilippe CharnierThe author of this software is 175a5941fc2SPhilippe Charnier.An David M. Gay . 17658f0484fSRodney W. Grimes.Pp 1773a5146d9SRuslan Ermilov.Bd -literal 178703d6560SDavid SchultzCopyright (c) 1998 by Lucent Technologies 179703d6560SDavid SchultzAll Rights Reserved 1803a5146d9SRuslan Ermilov 181703d6560SDavid SchultzPermission to use, copy, modify, and distribute this software and 182703d6560SDavid Schultzits documentation for any purpose and without fee is hereby 183703d6560SDavid Schultzgranted, provided that the above copyright notice appear in all 184703d6560SDavid Schultzcopies and that both that the copyright notice and this 185703d6560SDavid Schultzpermission notice and warranty disclaimer appear in supporting 186703d6560SDavid Schultzdocumentation, and that the name of Lucent or any of its entities 187703d6560SDavid Schultznot be used in advertising or publicity pertaining to 188703d6560SDavid Schultzdistribution of the software without specific, written prior 189703d6560SDavid Schultzpermission. 1903a5146d9SRuslan Ermilov 191703d6560SDavid SchultzLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 192703d6560SDavid SchultzINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. 193703d6560SDavid SchultzIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY 194703d6560SDavid SchultzSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 195703d6560SDavid SchultzWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 196703d6560SDavid SchultzIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 197703d6560SDavid SchultzARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 198703d6560SDavid SchultzTHIS SOFTWARE. 1993a5146d9SRuslan Ermilov.Ed 200