man-pages/man3/strtod.3.html
2021-03-31 01:06:50 +01:00

302 lines
6.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of STRTOD</TITLE>
</HEAD><BODY>
<H1>STRTOD</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
strtod, strtof, strtold - convert ASCII string to floating-point number
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;</B>
<P>
<B>double strtod(const char *</B><I>nptr</I><B>, char **</B><I>endptr</I><B>);</B>
<BR>
<B>float strtof(const char *</B><I>nptr</I><B>, char **</B><I>endptr</I><B>);</B>
<BR>
<B>long double strtold(const char *</B><I>nptr</I><B>, char **</B><I>endptr</I><B>);</B>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>strtof</B>(),
<B>strtold</B>():
<DL COMPACT><DT id="1"><DD>
_ISOC99_SOURCE || _POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200112L
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>strtod</B>(),
<B>strtof</B>(),
and
<B>strtold</B>()
functions convert the initial portion of the string pointed to by
<I>nptr</I>
to
<I>double</I>,
<I>float</I>,
and
<I>long double</I>
representation, respectively.
<P>
The expected form of the (initial portion of the) string is
optional leading white space as recognized by
<B><A HREF="/cgi-bin/man/man2html?3+isspace">isspace</A></B>(3),
an optional plus ('+') or minus sign ('-') and then either
(i) a decimal number, or (ii) a hexadecimal number,
or (iii) an infinity, or (iv) a NAN (not-a-number).
<P>
A
<I>decimal number</I>
consists of a nonempty sequence of decimal digits
possibly containing a radix character (decimal point, locale-dependent,
usually '.'), optionally followed by a decimal exponent.
A decimal exponent consists of an 'E' or 'e', followed by an
optional plus or minus sign, followed by a nonempty sequence of
decimal digits, and indicates multiplication by a power of 10.
<P>
A
<I>hexadecimal number</I>
consists of a &quot;0x&quot; or &quot;0X&quot; followed by a nonempty sequence of
hexadecimal digits possibly containing a radix character,
optionally followed by a binary exponent.
A binary exponent
consists of a 'P' or 'p', followed by an optional
plus or minus sign, followed by a nonempty sequence of
decimal digits, and indicates multiplication by a power of 2.
At least one of radix character and binary exponent must be present.
<P>
An
<I>infinity</I>
is either &quot;INF&quot; or &quot;INFINITY&quot;, disregarding case.
<P>
A
<I>NAN</I>
is &quot;NAN&quot; (disregarding case) optionally followed by a string,
<I>(n-char-sequence)</I>,
where
<I>n-char-sequence</I>
specifies in an implementation-dependent
way the type of NAN (see NOTES).
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
These functions return the converted value, if any.
<P>
If
<I>endptr</I>
is not NULL,
a pointer to the character after the last character used in the conversion
is stored in the location referenced by
<I>endptr</I>.
<P>
If no conversion is performed, zero is returned and (unless
<I>endptr</I>
is null) the value of
<I>nptr</I>
is stored in the location referenced by
<I>endptr</I>.
<P>
If the correct value would cause overflow, plus or minus
<B>HUGE_VAL</B>
(<B>HUGE_VALF</B>,
<B>HUGE_VALL</B>)
is returned (according to the sign of the value), and
<B>ERANGE</B>
is stored in
<I>errno</I>.
If the correct value would cause underflow, zero is
returned and
<B>ERANGE</B>
is stored in
<I>errno</I>.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="2"><B>ERANGE</B>
<DD>
Overflow or underflow occurred.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>strtod</B>(),
<B>strtof</B>(),
<B>strtold</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe locale<BR></TD></TR>
</TABLE>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008, C99.
<P>
<B>strtod</B>()
was also described in C89.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
Since
0 can legitimately be returned
on both success and failure, the calling program should set
<I>errno</I>
to 0 before the call,
and then determine if an error occurred by checking whether
<I>errno</I>
has a nonzero value after the call.
<P>
In the glibc implementation, the
<I>n-char-sequence</I>
that optionally follows &quot;NAN&quot;
is interpreted as an integer number
(with an optional '0' or '0x' prefix to select base 8 or 16)
that is to be placed in the
mantissa component of the returned value.
<A NAME="lbAJ">&nbsp;</A>
<H2>EXAMPLE</H2>
See the example on the
<B><A HREF="/cgi-bin/man/man2html?3+strtol">strtol</A></B>(3)
manual page;
the use of the functions described in this manual page is similar.
<A NAME="lbAK">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+atof">atof</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+atoi">atoi</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+atol">atol</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+nan">nan</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+nanf">nanf</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+nanl">nanl</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+strfromd">strfromd</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+strtol">strtol</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+strtoul">strtoul</A></B>(3)
<A NAME="lbAL">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="3"><A HREF="#lbAB">NAME</A><DD>
<DT id="4"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="5"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="6"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="7"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="8"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="9"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="10"><A HREF="#lbAI">NOTES</A><DD>
<DT id="11"><A HREF="#lbAJ">EXAMPLE</A><DD>
<DT id="12"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="13"><A HREF="#lbAL">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:58 GMT, March 31, 2021
</BODY>
</HTML>