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. 16*580b4d18SEd Maste.\" 3. 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.\" 32e91cb7f0SChristian Brueffer.Dd May 11, 2010 3358f0484fSRodney W. Grimes.Dt STRTOD 3 3458f0484fSRodney W. Grimes.Os 3558f0484fSRodney W. Grimes.Sh NAME 36703d6560SDavid Schultz.Nm strtod , strtof , strtold 3758f0484fSRodney W. Grimes.Nd convert 3858f0484fSRodney W. Grimes.Tn ASCII 39703d6560SDavid Schultzstring to floating point 4025bb73e0SAlexey Zelkin.Sh LIBRARY 4125bb73e0SAlexey Zelkin.Lb libc 4258f0484fSRodney W. Grimes.Sh SYNOPSIS 438aefde06SJeroen Ruigrok van der Werven.In stdlib.h 4458f0484fSRodney W. Grimes.Ft double 455618f724SRobert Drehmel.Fn strtod "const char * restrict nptr" "char ** restrict endptr" 46703d6560SDavid Schultz.Ft float 47703d6560SDavid Schultz.Fn strtof "const char * restrict nptr" "char ** restrict endptr" 483a5146d9SRuslan Ermilov.Ft "long double" 49703d6560SDavid Schultz.Fn strtold "const char * restrict nptr" "char ** restrict endptr" 5058f0484fSRodney W. Grimes.Sh DESCRIPTION 51703d6560SDavid SchultzThese conversion 52703d6560SDavid Schultzfunctions convert the initial portion of the string 5358f0484fSRodney W. Grimespointed to by 5458f0484fSRodney W. Grimes.Fa nptr 5558f0484fSRodney W. Grimesto 56703d6560SDavid Schultz.Vt double , 57703d6560SDavid Schultz.Vt float , 58703d6560SDavid Schultzand 593a5146d9SRuslan Ermilov.Vt "long double" 60703d6560SDavid Schultzrepresentation, respectively. 6158f0484fSRodney W. Grimes.Pp 6258f0484fSRodney W. GrimesThe expected form of the string is an optional plus (``+'') or minus 63703d6560SDavid Schultzsign (``\-'') followed by either: 64703d6560SDavid Schultz.Bl -bullet 65703d6560SDavid Schultz.It 66703d6560SDavid Schultza decimal significand consisting of a sequence of decimal digits 67703d6560SDavid Schultzoptionally containing a decimal-point character, or 68703d6560SDavid Schultz.It 69703d6560SDavid Schultza hexadecimal significand consisting of a ``0X'' or ``0x'' followed 70703d6560SDavid Schultzby a sequence of hexadecimal digits optionally containing a 71703d6560SDavid Schultzdecimal-point character. 72703d6560SDavid Schultz.El 7358f0484fSRodney W. Grimes.Pp 74703d6560SDavid SchultzIn both cases, the significand may be optionally followed by an 75703d6560SDavid Schultzexponent. 76703d6560SDavid SchultzAn exponent consists of an ``E'' or ``e'' (for decimal 77703d6560SDavid Schultzconstants) or a ``P'' or ``p'' (for hexadecimal constants), 78703d6560SDavid Schultzfollowed by an optional plus or minus sign, followed by a 79703d6560SDavid Schultzsequence of decimal digits. 80703d6560SDavid SchultzFor decimal constants, the exponent indicates the power of 10 by 81703d6560SDavid Schultzwhich the significand should be scaled. 82703d6560SDavid SchultzFor hexadecimal constants, the scaling is instead done by powers 83703d6560SDavid Schultzof 2. 84703d6560SDavid Schultz.Pp 85703d6560SDavid SchultzAlternatively, if the portion of the string following the optional 864b6b5744SDavid Schultzplus or minus sign begins with 874b6b5744SDavid Schultz.Dq INFINITY 884b6b5744SDavid Schultzor 894b6b5744SDavid Schultz.Dq NAN , 904b6b5744SDavid Schultzignoring case, it is interpreted as an infinity or a quiet \*(Na, 914b6b5744SDavid Schultzrespectively. 924b6b5744SDavid SchultzThe syntax 934b6b5744SDavid Schultz.Dq Xo Pf NAN( Ar "s" ) Xc , 944b6b5744SDavid Schultzwhere 954b6b5744SDavid Schultz.Ar s 964b6b5744SDavid Schultzis an alphanumeric string, produces the same value as the call 974b6b5744SDavid Schultz.Fo nan 984b6b5744SDavid Schultz.Qq Ar s Ns 994b6b5744SDavid Schultz.Fc 1004b6b5744SDavid Schultz(respectively, 1014b6b5744SDavid Schultz.Fo nanf 1024b6b5744SDavid Schultz.Qq Ar s Ns 1034b6b5744SDavid Schultz.Fc 1044b6b5744SDavid Schultzand 1054b6b5744SDavid Schultz.Fo nanl 1064b6b5744SDavid Schultz.Qq Ar s Ns 1074b6b5744SDavid Schultz.Fc . ) 108703d6560SDavid Schultz.Pp 109703d6560SDavid SchultzIn any of the above cases, leading white-space characters in the 110703d6560SDavid Schultzstring (as defined by the 11158f0484fSRodney W. Grimes.Xr isspace 3 11258f0484fSRodney W. Grimesfunction) are skipped. 11305a6e1e5SAndrey A. ChernovThe decimal point 114429d919cSRuslan Ermilovcharacter is defined in the program's locale (category 115429d919cSRuslan Ermilov.Dv LC_NUMERIC ) . 11658f0484fSRodney W. Grimes.Sh RETURN VALUES 11758f0484fSRodney W. GrimesThe 118703d6560SDavid Schultz.Fn strtod , 119703d6560SDavid Schultz.Fn strtof , 120703d6560SDavid Schultzand 121703d6560SDavid Schultz.Fn strtold 122703d6560SDavid Schultzfunctions return the converted value, if any. 12358f0484fSRodney W. Grimes.Pp 12458f0484fSRodney W. GrimesIf 12558f0484fSRodney W. Grimes.Fa endptr 12658f0484fSRodney W. Grimesis not 12758f0484fSRodney W. Grimes.Dv NULL , 12858f0484fSRodney W. Grimesa pointer to the character after the last character used 12958f0484fSRodney W. Grimesin the conversion is stored in the location referenced by 13058f0484fSRodney W. Grimes.Fa endptr . 13158f0484fSRodney W. Grimes.Pp 13258f0484fSRodney W. GrimesIf no conversion is performed, zero is returned and the value of 13358f0484fSRodney W. Grimes.Fa nptr 13458f0484fSRodney W. Grimesis stored in the location referenced by 13558f0484fSRodney W. Grimes.Fa endptr . 13658f0484fSRodney W. Grimes.Pp 13758f0484fSRodney W. GrimesIf the correct value would cause overflow, plus or minus 138703d6560SDavid Schultz.Dv HUGE_VAL , 139703d6560SDavid Schultz.Dv HUGE_VALF , 140703d6560SDavid Schultzor 141703d6560SDavid Schultz.Dv HUGE_VALL 142703d6560SDavid Schultzis returned (according to the sign and type of the return value), and 143c23155a4SRuslan Ermilov.Er ERANGE 14458f0484fSRodney W. Grimesis stored in 14558f0484fSRodney W. Grimes.Va errno . 14658f0484fSRodney W. GrimesIf the correct value would cause underflow, zero is 14758f0484fSRodney W. Grimesreturned and 148c23155a4SRuslan Ermilov.Er ERANGE 14958f0484fSRodney W. Grimesis stored in 15058f0484fSRodney W. Grimes.Va errno . 15158f0484fSRodney W. Grimes.Sh ERRORS 152274b6244SAlexey Zelkin.Bl -tag -width Er 15358f0484fSRodney W. Grimes.It Bq Er ERANGE 15458f0484fSRodney W. GrimesOverflow or underflow occurred. 15542635956SRuslan Ermilov.El 15658f0484fSRodney W. Grimes.Sh SEE ALSO 15758f0484fSRodney W. Grimes.Xr atof 3 , 15858f0484fSRodney W. Grimes.Xr atoi 3 , 15958f0484fSRodney W. Grimes.Xr atol 3 , 1604b6b5744SDavid Schultz.Xr nan 3 , 16158f0484fSRodney W. Grimes.Xr strtol 3 , 162ecab372bSTim J. Robbins.Xr strtoul 3 , 163ecab372bSTim J. Robbins.Xr wcstod 3 16458f0484fSRodney W. Grimes.Sh STANDARDS 16558f0484fSRodney W. GrimesThe 16658f0484fSRodney W. Grimes.Fn strtod 16758f0484fSRodney W. Grimesfunction 16858f0484fSRodney W. Grimesconforms to 169e91cb7f0SChristian Brueffer.St -isoC-99 . 17058f0484fSRodney W. Grimes.Sh AUTHORS 171a5941fc2SPhilippe CharnierThe author of this software is 172a5941fc2SPhilippe Charnier.An David M. Gay . 1733a5146d9SRuslan Ermilov.Bd -literal 174703d6560SDavid SchultzCopyright (c) 1998 by Lucent Technologies 175703d6560SDavid SchultzAll Rights Reserved 1763a5146d9SRuslan Ermilov 177703d6560SDavid SchultzPermission to use, copy, modify, and distribute this software and 178703d6560SDavid Schultzits documentation for any purpose and without fee is hereby 179703d6560SDavid Schultzgranted, provided that the above copyright notice appear in all 180703d6560SDavid Schultzcopies and that both that the copyright notice and this 181703d6560SDavid Schultzpermission notice and warranty disclaimer appear in supporting 182703d6560SDavid Schultzdocumentation, and that the name of Lucent or any of its entities 183703d6560SDavid Schultznot be used in advertising or publicity pertaining to 184703d6560SDavid Schultzdistribution of the software without specific, written prior 185703d6560SDavid Schultzpermission. 1863a5146d9SRuslan Ermilov 187703d6560SDavid SchultzLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 188703d6560SDavid SchultzINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. 189703d6560SDavid SchultzIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY 190703d6560SDavid SchultzSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 191703d6560SDavid SchultzWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 192703d6560SDavid SchultzIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 193703d6560SDavid SchultzARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 194703d6560SDavid SchultzTHIS SOFTWARE. 1953a5146d9SRuslan Ermilov.Ed 196