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

365 lines
7.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of STRFROMD</TITLE>
</HEAD><BODY>
<H1>STRFROMD</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<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>
strfromd, strfromf, strfroml - convert a floating-point value into
a string
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;</B>
<B>int strfromd(char *restrict </B><I>str</I><B>, size_t </B><I>n</I><B>,</B>
<B> const char *restrict </B><I>format</I><B>, double </B><I>fp</I><B>);</B>
<B>int strfromf(char *restrict </B><I>str</I><B>, size_t </B><I>n</I><B>,</B>
<B> const char *restrict </B><I>format</I><B>, float fp</B><I>);</I>
<B>int strfroml(char *restrict </B><I>str</I><B>, size_t </B><I>n</I><B>,</B>
<B> const char *restrict </B><I>format</I><B>, long double </B><I>fp</I><B>);</B>
</PRE>
<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>strfromd</B>(),
<B>strfromf</B>(),
<B>strfroml</B>():
<DL COMPACT><DT id="1"><DD>
__STDC_WANT_IEC_60559_BFP_EXT__
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
These functions convert a floating-point value,
<I>fp</I>,
into a string of characters,
<I>str</I>,
with a configurable
<I>format</I>
string.
At most
<I>n</I>
characters are stored into
<I>str</I>.
<P>
The terminating null character ('\0') is written if and only if
<I>n</I>
is sufficiently large, otherwise the written string is truncated at
<I>n</I>
characters.
<P>
The
<B>strfromd</B>(),
<B>strfromf</B>(),
and
<B>strfroml</B>()
functions are equivalent to
<P>
snprintf(str, n, format, fp);
<P>
except for the
<I>format</I>
string.
<A NAME="lbAE">&nbsp;</A>
<H3>Format of the format string</H3>
The
<I>format</I>
string must start with the character '%'.
This is followed by an optional precision which starts with the period
character (.), followed by an optional decimal integer.
If no integer is specified after the period character,
a precision of zero is used.
Finally, the format string should have one of the conversion specifiers
<B>a</B>,
<B>A</B>,
<B>e</B>,
<B>E</B>,
<B>f</B>,
<B>F</B>,
<B>g</B>,
or
<B>G</B>.
<P>
The conversion specifier is applied based on the floating-point type
indicated by the function suffix.
Therefore, unlike
<B>snprintf</B>(),
the format string does not have a length modifier character.
See
<B><A HREF="/cgi-bin/man/man2html?3+snprintf">snprintf</A></B>(3)
for a detailed description of these conversion specifiers.
<P>
The implementation conforms to the C99 standard on conversion of NaN and
infinity values:
<P>
<DL COMPACT><DT id="2"><DD>
If
<I>fp</I>
is a NaN, +NaN, or -NaN, and
<B>f</B>
(or
<B>a</B>,
<B>e</B>,
<B>g</B>)
is the conversion specifier, the conversion is to &quot;nan&quot;, &quot;nan&quot;, or &quot;-nan&quot;,
respectively.
If
<B>F</B>
(or
<B>A</B>,
<B>E</B>,
<B>G</B>)
is the conversion specifier, the conversion is to &quot;NAN&quot; or &quot;-NAN&quot;.
<P>
Likewise if
<I>fp</I>
is infinity, it is converted to [-]inf or [-]INF.
</DL>
<P>
A malformed
<I>format</I>
string results in undefined behavior.
<A NAME="lbAF">&nbsp;</A>
<H2>RETURN VALUE</H2>
The
<B>strfromd</B>(),
<B>strfromf</B>(),
and
<B>strfroml</B>()
functions return the number of characters that would have been written in
<I>str</I>
if
<I>n</I>
had enough space,
not counting the terminating null character.
Thus, a return value of
<I>n</I>
or greater means that the output was truncated.
<A NAME="lbAG">&nbsp;</A>
<H2>VERSIONS</H2>
The
<B>strfromd</B>(),
<B>strfromf</B>(),
and
<B>strfroml</B>()
functions are available in glibc since version 2.25.
<A NAME="lbAH">&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)
and the
<B>POSIX Safety Concepts</B>
section in GNU C Library manual.
<P>
<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 VALIGN=center ROWSPAN=2>
<B>strfromd</B>(),
<B>strfromf</B>(),
<B>strfroml</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe locale<BR></TD></TR>
<TR VALIGN=top><TD>Asynchronous signal safety</TD><TD>AS-Unsafe heap</TD></TR>
<TR VALIGN=top><TD>Asynchronous cancellation safety</TD><TD>AC-Unsafe mem</TD></TR>
</TABLE>
<P>
Note: these attributes are preliminary.
<A NAME="lbAI">&nbsp;</A>
<H2>CONFORMING TO</H2>
C99, ISO/IEC TS 18661-1.
<A NAME="lbAJ">&nbsp;</A>
<H2>NOTES</H2>
The
<B>strfromd</B>(),
<B>strfromf</B>(),
and
<B>strfroml</B>()
functions take account of the
<B>LC_NUMERIC</B>
category of the current locale.
<A NAME="lbAK">&nbsp;</A>
<H2>EXAMPLES</H2>
To convert the value 12.1 as a float type to a string using decimal
notation, resulting in &quot;12.100000&quot;:
<P>
#define __STDC_WANT_IEC_60559_BFP_EXT__
#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;
int ssize = 10;
char s[ssize];
strfromf(s, ssize, &quot;%f&quot;, 12.1);
<P>
To convert the value 12.3456 as a float type to a string using
decimal notation with two digits of precision, resulting in &quot;12.35&quot;:
<P>
#define __STDC_WANT_IEC_60559_BFP_EXT__
#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;
int ssize = 10;
char s[ssize];
strfromf(s, ssize, &quot;%.2f&quot;, 12.3456);
<P>
To convert the value 12.345e19 as a double type to a string using
scientific notation with zero digits of precision, resulting in &quot;1E+20&quot;:
<P>
#define __STDC_WANT_IEC_60559_BFP_EXT__
#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;
int ssize = 10;
char s[ssize];
strfromd(s, ssize, &quot;%.E&quot;, 12.345e19);
<A NAME="lbAL">&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+snprintf">snprintf</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+strtod">strtod</A></B>(3)
<A NAME="lbAM">&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>
<DL>
<DT id="6"><A HREF="#lbAE">Format of the format string</A><DD>
</DL>
<DT id="7"><A HREF="#lbAF">RETURN VALUE</A><DD>
<DT id="8"><A HREF="#lbAG">VERSIONS</A><DD>
<DT id="9"><A HREF="#lbAH">ATTRIBUTES</A><DD>
<DT id="10"><A HREF="#lbAI">CONFORMING TO</A><DD>
<DT id="11"><A HREF="#lbAJ">NOTES</A><DD>
<DT id="12"><A HREF="#lbAK">EXAMPLES</A><DD>
<DT id="13"><A HREF="#lbAL">SEE ALSO</A><DD>
<DT id="14"><A HREF="#lbAM">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>