xref: /freebsd/lib/libc/stdlib/strtod.3 (revision 3a5146d9e27e4472cb615d1d5e7027d0e331bec3)
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.\" 3. All advertising materials mentioning features or use of this software
1758f0484fSRodney W. Grimes.\"    must display the following acknowledgement:
1858f0484fSRodney W. Grimes.\"	This product includes software developed by the University of
1958f0484fSRodney W. Grimes.\"	California, Berkeley and its contributors.
2058f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
2158f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
2258f0484fSRodney W. Grimes.\"    without specific prior written permission.
2358f0484fSRodney W. Grimes.\"
2458f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2558f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2658f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2758f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2858f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2958f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3058f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3158f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3258f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3358f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3458f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3558f0484fSRodney W. Grimes.\"
3658f0484fSRodney W. Grimes.\"     @(#)strtod.3	8.1 (Berkeley) 6/4/93
377f3dea24SPeter Wemm.\" $FreeBSD$
3858f0484fSRodney W. Grimes.\"
39703d6560SDavid Schultz.Dd March 2, 2003
4058f0484fSRodney W. Grimes.Dt STRTOD 3
4158f0484fSRodney W. Grimes.Os
4258f0484fSRodney W. Grimes.Sh NAME
43703d6560SDavid Schultz.Nm strtod , strtof , strtold
4458f0484fSRodney W. Grimes.Nd convert
4558f0484fSRodney W. Grimes.Tn ASCII
46703d6560SDavid Schultzstring to floating point
4725bb73e0SAlexey Zelkin.Sh LIBRARY
4825bb73e0SAlexey Zelkin.Lb libc
4958f0484fSRodney W. Grimes.Sh SYNOPSIS
508aefde06SJeroen Ruigrok van der Werven.In stdlib.h
5158f0484fSRodney W. Grimes.Ft double
525618f724SRobert Drehmel.Fn strtod "const char * restrict nptr" "char ** restrict endptr"
53703d6560SDavid Schultz.Ft float
54703d6560SDavid Schultz.Fn strtof "const char * restrict nptr" "char ** restrict endptr"
553a5146d9SRuslan Ermilov.Ft "long double"
56703d6560SDavid Schultz.Fn strtold "const char * restrict nptr" "char ** restrict endptr"
5758f0484fSRodney W. Grimes.Sh DESCRIPTION
58703d6560SDavid SchultzThese conversion
59703d6560SDavid Schultzfunctions convert the initial portion of the string
6058f0484fSRodney W. Grimespointed to by
6158f0484fSRodney W. Grimes.Fa nptr
6258f0484fSRodney W. Grimesto
63703d6560SDavid Schultz.Vt double ,
64703d6560SDavid Schultz.Vt float ,
65703d6560SDavid Schultzand
663a5146d9SRuslan Ermilov.Vt "long double"
67703d6560SDavid Schultzrepresentation, respectively.
6858f0484fSRodney W. Grimes.Pp
6958f0484fSRodney W. GrimesThe expected form of the string is an optional plus (``+'') or minus
70703d6560SDavid Schultzsign (``\-'') followed by either:
71703d6560SDavid Schultz.Bl -bullet
72703d6560SDavid Schultz.It
73703d6560SDavid Schultza decimal significand consisting of a sequence of decimal digits
74703d6560SDavid Schultzoptionally containing a decimal-point character, or
75703d6560SDavid Schultz.It
76703d6560SDavid Schultza hexadecimal significand consisting of a ``0X'' or ``0x'' followed
77703d6560SDavid Schultzby a sequence of hexadecimal digits optionally containing a
78703d6560SDavid Schultzdecimal-point character.
79703d6560SDavid Schultz.El
8058f0484fSRodney W. Grimes.Pp
81703d6560SDavid SchultzIn both cases, the significand may be optionally followed by an
82703d6560SDavid Schultzexponent.
83703d6560SDavid SchultzAn exponent consists of an ``E'' or ``e'' (for decimal
84703d6560SDavid Schultzconstants) or a ``P'' or ``p'' (for hexadecimal constants),
85703d6560SDavid Schultzfollowed by an optional plus or minus sign, followed by a
86703d6560SDavid Schultzsequence of decimal digits.
87703d6560SDavid SchultzFor decimal constants, the exponent indicates the power of 10 by
88703d6560SDavid Schultzwhich the significand should be scaled.
89703d6560SDavid SchultzFor hexadecimal constants, the scaling is instead done by powers
90703d6560SDavid Schultzof 2.
91703d6560SDavid Schultz.Pp
92703d6560SDavid SchultzAlternatively, if the portion of the string following the optional
93703d6560SDavid Schultzplus or minus sign begins with ``INFINITY'' or ``NAN'', ignoring
94703d6560SDavid Schultzcase, it is interpreted as an infinity or a quiet NaN, respectively.
95703d6560SDavid Schultz.Pp
96703d6560SDavid SchultzIn any of the above cases, leading white-space characters in the
97703d6560SDavid Schultzstring (as defined by the
9858f0484fSRodney W. Grimes.Xr isspace 3
9958f0484fSRodney W. Grimesfunction) are skipped.
10005a6e1e5SAndrey A. ChernovThe decimal point
101429d919cSRuslan Ermilovcharacter is defined in the program's locale (category
102429d919cSRuslan Ermilov.Dv LC_NUMERIC ) .
10358f0484fSRodney W. Grimes.Sh RETURN VALUES
10458f0484fSRodney W. GrimesThe
105703d6560SDavid Schultz.Fn strtod ,
106703d6560SDavid Schultz.Fn strtof ,
107703d6560SDavid Schultzand
108703d6560SDavid Schultz.Fn strtold
109703d6560SDavid Schultzfunctions return the converted value, if any.
11058f0484fSRodney W. Grimes.Pp
11158f0484fSRodney W. GrimesIf
11258f0484fSRodney W. Grimes.Fa endptr
11358f0484fSRodney W. Grimesis not
11458f0484fSRodney W. Grimes.Dv NULL ,
11558f0484fSRodney W. Grimesa pointer to the character after the last character used
11658f0484fSRodney W. Grimesin the conversion is stored in the location referenced by
11758f0484fSRodney W. Grimes.Fa endptr .
11858f0484fSRodney W. Grimes.Pp
11958f0484fSRodney W. GrimesIf no conversion is performed, zero is returned and the value of
12058f0484fSRodney W. Grimes.Fa nptr
12158f0484fSRodney W. Grimesis stored in the location referenced by
12258f0484fSRodney W. Grimes.Fa endptr .
12358f0484fSRodney W. Grimes.Pp
12458f0484fSRodney W. GrimesIf the correct value would cause overflow, plus or minus
125703d6560SDavid Schultz.Dv HUGE_VAL ,
126703d6560SDavid Schultz.Dv HUGE_VALF ,
127703d6560SDavid Schultzor
128703d6560SDavid Schultz.Dv HUGE_VALL
129703d6560SDavid Schultzis returned (according to the sign and type of the return value), and
130c23155a4SRuslan Ermilov.Er ERANGE
13158f0484fSRodney W. Grimesis stored in
13258f0484fSRodney W. Grimes.Va errno .
13358f0484fSRodney W. GrimesIf the correct value would cause underflow, zero is
13458f0484fSRodney W. Grimesreturned and
135c23155a4SRuslan Ermilov.Er ERANGE
13658f0484fSRodney W. Grimesis stored in
13758f0484fSRodney W. Grimes.Va errno .
13858f0484fSRodney W. Grimes.Sh ERRORS
139274b6244SAlexey Zelkin.Bl -tag -width Er
14058f0484fSRodney W. Grimes.It Bq Er ERANGE
14158f0484fSRodney W. GrimesOverflow or underflow occurred.
14242635956SRuslan Ermilov.El
14358f0484fSRodney W. Grimes.Sh SEE ALSO
14458f0484fSRodney W. Grimes.Xr atof 3 ,
14558f0484fSRodney W. Grimes.Xr atoi 3 ,
14658f0484fSRodney W. Grimes.Xr atol 3 ,
14758f0484fSRodney W. Grimes.Xr strtol 3 ,
148ecab372bSTim J. Robbins.Xr strtoul 3 ,
149ecab372bSTim J. Robbins.Xr wcstod 3
15058f0484fSRodney W. Grimes.Sh STANDARDS
15158f0484fSRodney W. GrimesThe
15258f0484fSRodney W. Grimes.Fn strtod
15358f0484fSRodney W. Grimesfunction
15458f0484fSRodney W. Grimesconforms to
155703d6560SDavid Schultz.St -isoC-99 ,
156703d6560SDavid Schultzwith the exception of the bug noted below.
157703d6560SDavid Schultz.Sh BUGS
158703d6560SDavid SchultzThese routines do not recognize the C99 ``NaN(...)'' syntax.
15958f0484fSRodney W. Grimes.Sh AUTHORS
160a5941fc2SPhilippe CharnierThe author of this software is
161a5941fc2SPhilippe Charnier.An David M. Gay .
16258f0484fSRodney W. Grimes.Pp
1633a5146d9SRuslan Ermilov.Bd -literal
164703d6560SDavid SchultzCopyright (c) 1998 by Lucent Technologies
165703d6560SDavid SchultzAll Rights Reserved
1663a5146d9SRuslan Ermilov
167703d6560SDavid SchultzPermission to use, copy, modify, and distribute this software and
168703d6560SDavid Schultzits documentation for any purpose and without fee is hereby
169703d6560SDavid Schultzgranted, provided that the above copyright notice appear in all
170703d6560SDavid Schultzcopies and that both that the copyright notice and this
171703d6560SDavid Schultzpermission notice and warranty disclaimer appear in supporting
172703d6560SDavid Schultzdocumentation, and that the name of Lucent or any of its entities
173703d6560SDavid Schultznot be used in advertising or publicity pertaining to
174703d6560SDavid Schultzdistribution of the software without specific, written prior
175703d6560SDavid Schultzpermission.
1763a5146d9SRuslan Ermilov
177703d6560SDavid SchultzLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
178703d6560SDavid SchultzINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
179703d6560SDavid SchultzIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
180703d6560SDavid SchultzSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
181703d6560SDavid SchultzWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
182703d6560SDavid SchultzIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
183703d6560SDavid SchultzARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
184703d6560SDavid SchultzTHIS SOFTWARE.
1853a5146d9SRuslan Ermilov.Ed
186