]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/strfromd.3
All pages: Remove the 5th argument to .TH
[thirdparty/man-pages.git] / man3 / strfromd.3
CommitLineData
d8be6d2b
WSM
1.\" Copyright (c) 2016, IBM Corporation.
2.\" Written by Wainer dos Santos Moschetta <wainersm@linux.vnet.ibm.com>
3.\"
5fbde956 4.\" SPDX-License-Identifier: Linux-man-pages-copyleft
d8be6d2b
WSM
5.\"
6.\" References consulted:
7.\" Glibc 2.25 source code and manual.
8.\" C99 standard document.
9.\" ISO/IEC TS 18661-1 technical specification.
10.\" snprintf and other man.3 pages.
11.\"
45186a5d 12.TH STRFROMD 3 2021-03-22 "Linux man-pages (unreleased)"
d8be6d2b
WSM
13.SH NAME
14strfromd, strfromf, strfroml \- convert a floating-point value into
f75bdcaf 15a string
dc43ca74
AC
16.SH LIBRARY
17Standard C library
8fc3b2cf 18.RI ( libc ", " \-lc )
d8be6d2b 19.SH SYNOPSIS
f75bdcaf 20.nf
d8be6d2b 21.B #include <stdlib.h>
f90f031e 22.PP
9bfc9cb1 23.BI "int strfromd(char *restrict " str ", size_t " n ,
f75bdcaf 24.BI " const char *restrict " format ", double " fp ");"
9bfc9cb1 25.BI "int strfromf(char *restrict " str ", size_t " n ,
f75bdcaf 26.BI " const char *restrict " format ", float "fp ");"
9bfc9cb1 27.BI "int strfroml(char *restrict " str ", size_t " n ,
f75bdcaf
MK
28.BI " const char *restrict " format ", long double " fp ");"
29.fi
f90f031e 30.PP
d39ad78f 31.RS -4
d8be6d2b
WSM
32Feature Test Macro Requirements for glibc (see
33.BR feature_test_macros (7)):
d39ad78f 34.RE
68e4db0a 35.PP
d8be6d2b
WSM
36.BR strfromd (),
37.BR strfromf (),
38.BR strfroml ():
9d2adbae
MK
39.nf
40 __STDC_WANT_IEC_60559_BFP_EXT__
41.fi
d8be6d2b 42.SH DESCRIPTION
f75bdcaf
MK
43These functions convert a floating-point value,
44.IR fp ,
45into a string of characters,
d8be6d2b
WSM
46.IR str ,
47with a configurable
1ae6b2c7 48.I format
d8be6d2b
WSM
49string.
50At most
51.I n
52characters are stored into
53.IR str .
51f5698d 54.PP
c5c0846d 55The terminating null byte ('\e0') is written if and only if
d8be6d2b
WSM
56.I n
57is sufficiently large, otherwise the written string is truncated at
58.I n
59characters.
51f5698d 60.PP
d8be6d2b
WSM
61The
62.BR strfromd (),
63.BR strfromf (),
64and
65.BR strfroml ()
66functions are equivalent to
847e0d88 67.PP
bdd915e2
MK
68.in +4n
69.EX
70snprintf(str, n, format, fp);
71.EE
72.in
847e0d88 73.PP
d8be6d2b
WSM
74except for the
75.I format
76string.
77.SS Format of the format string
78The
79.I format
f75bdcaf
MK
80string must start with the character \(aq%\(aq.
81This is followed by an optional precision which starts with the period
d8be6d2b 82character (.), followed by an optional decimal integer.
f75bdcaf
MK
83If no integer is specified after the period character,
84a precision of zero is used.
85Finally, the format string should have one of the conversion specifiers
d8be6d2b
WSM
86.BR a ,
87.BR A ,
88.BR e ,
89.BR E ,
90.BR f ,
91.BR F ,
92.BR g ,
93or
94.BR G .
51f5698d 95.PP
d8be6d2b
WSM
96The conversion specifier is applied based on the floating-point type
97indicated by the function suffix.
98Therefore, unlike
99.BR snprintf (),
100the format string does not have a length modifier character.
101See
102.BR snprintf (3)
103for a detailed description of these conversion specifiers.
51f5698d 104.PP
d8be6d2b
WSM
105The implementation conforms to the C99 standard on conversion of NaN and
106infinity values:
847e0d88 107.PP
f75bdcaf 108.RS
d8be6d2b
WSM
109If
110.I fp
b3bb3f58 111is a NaN, +NaN, or \-NaN, and
1ae6b2c7 112.B f
d8be6d2b
WSM
113(or
114.BR a ,
115.BR e ,
116.BR g )
b3bb3f58 117is the conversion specifier, the conversion is to "nan", "nan", or "\-nan",
d8be6d2b
WSM
118respectively.
119If
120.B F
121(or
122.BR A ,
123.BR E ,
124.BR G )
b3bb3f58 125is the conversion specifier, the conversion is to "NAN" or "\-NAN".
51f5698d 126.PP
d8be6d2b
WSM
127Likewise if
128.I fp
b3bb3f58 129is infinity, it is converted to [\-]inf or [\-]INF.
f75bdcaf 130.RE
847e0d88 131.PP
d8be6d2b
WSM
132A malformed
133.I format
134string results in undefined behavior.
135.SH RETURN VALUE
136The
137.BR strfromd (),
138.BR strfromf (),
139and
140.BR strfroml ()
141functions return the number of characters that would have been written in
142.I str
143if
144.I n
145had enough space,
c5c0846d 146not counting the terminating null byte.
d8be6d2b
WSM
147Thus, a return value of
148.I n
149or greater means that the output was truncated.
150.SH VERSIONS
151The
152.BR strfromd (),
153.BR strfromf (),
154and
155.BR strfroml ()
156functions are available in glibc since version 2.25.
157.SH ATTRIBUTES
158For an explanation of the terms used in this section, see
159.BR attributes (7)
160and the
161.B POSIX Safety Concepts
162section in GNU C Library manual.
51f5698d 163.PP
c466875e
MK
164.ad l
165.nh
d8be6d2b
WSM
166.TS
167allbox;
c466875e 168lbx lb lb
d8be6d2b
WSM
169l l l.
170Interface Attribute Value
171T{
172.BR strfromd (),
173.BR strfromf (),
174.BR strfroml ()
175T} Thread safety MT-Safe locale
b32feea5
MK
176\^ Async-signal safety AS-Unsafe heap
177\^ Async-cancel safety AC-Unsafe mem
d8be6d2b 178.TE
c466875e
MK
179.hy
180.ad
bdd915e2 181.sp 1
d8be6d2b 182Note: these attributes are preliminary.
3113c7f3 183.SH STANDARDS
d8be6d2b
WSM
184C99, ISO/IEC TS 18661-1.
185.SH NOTES
f75bdcaf 186The
d8be6d2b
WSM
187.BR strfromd (),
188.BR strfromf (),
189and
190.BR strfroml ()
191functions take account of the
192.B LC_NUMERIC
193category of the current locale.
d8be6d2b
WSM
194.SH EXAMPLES
195To convert the value 12.1 as a float type to a string using decimal
196notation, resulting in "12.100000":
51f5698d 197.PP
161b8eda 198.in +4n
bdd915e2 199.EX
d8be6d2b
WSM
200#define __STDC_WANT_IEC_60559_BFP_EXT__
201#include <stdlib.h>
202int ssize = 10;
203char s[ssize];
204strfromf(s, ssize, "%f", 12.1);
bdd915e2 205.EE
d8be6d2b 206.in
51f5698d 207.PP
d8be6d2b
WSM
208To convert the value 12.3456 as a float type to a string using
209decimal notation with two digits of precision, resulting in "12.35":
51f5698d 210.PP
161b8eda 211.in +4n
bdd915e2 212.EX
d8be6d2b
WSM
213#define __STDC_WANT_IEC_60559_BFP_EXT__
214#include <stdlib.h>
215int ssize = 10;
216char s[ssize];
217strfromf(s, ssize, "%.2f", 12.3456);
bdd915e2 218.EE
d8be6d2b 219.in
51f5698d 220.PP
d8be6d2b
WSM
221To convert the value 12.345e19 as a double type to a string using
222scientific notation with zero digits of precision, resulting in "1E+20":
51f5698d 223.PP
161b8eda 224.in +4n
bdd915e2 225.EX
d8be6d2b
WSM
226#define __STDC_WANT_IEC_60559_BFP_EXT__
227#include <stdlib.h>
228int ssize = 10;
229char s[ssize];
230strfromd(s, ssize, "%.E", 12.345e19);
bdd915e2 231.EE
d8be6d2b
WSM
232.in
233.SH SEE ALSO
234.BR atof (3),
235.BR snprintf (3),
236.BR strtod (3)