1 .\" Copyright (c) 2016, IBM Corporation.
2 .\" Written by Wainer dos Santos Moschetta <wainersm@linux.vnet.ibm.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of
10 .\" this manual under the conditions for verbatim copying, provided that
11 .\" the entire resulting derived work is distributed under the terms of
12 .\" a permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume.
16 .\" no responsibility for errors or omissions, or for damages resulting.
17 .\" from the use of the information contained herein. The author(s) may.
18 .\" not have taken the same level of care in the production of this.
19 .\" manual, which is licensed free of charge, as they might when working.
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" References consulted:
27 .\" Glibc 2.25 source code and manual.
28 .\" C99 standard document.
29 .\" ISO/IEC TS 18661-1 technical specification.
30 .\" snprintf and other man.3 pages.
32 .TH STRFROMD 3 2021-03-22 "GNU" "Linux Programmer's Manual"
34 strfromd, strfromf, strfroml \- convert a floating-point value into
38 .B #include <stdlib.h>
40 .BI "int strfromd(char *restrict " str ", size_t " n ,
41 .BI " const char *restrict " format ", double " fp ");"
42 .BI "int strfromf(char *restrict " str ", size_t " n ,
43 .BI " const char *restrict " format ", float "fp ");"
44 .BI "int strfroml(char *restrict " str ", size_t " n ,
45 .BI " const char *restrict " format ", long double " fp ");"
49 Feature Test Macro Requirements for glibc (see
50 .BR feature_test_macros (7)):
57 __STDC_WANT_IEC_60559_BFP_EXT__
60 These functions convert a floating-point value,
62 into a string of characters,
69 characters are stored into
72 The terminating null byte ('\e0') is written if and only if
74 is sufficiently large, otherwise the written string is truncated at
83 functions are equivalent to
87 snprintf(str, n, format, fp);
94 .SS Format of the format string
97 string must start with the character \(aq%\(aq.
98 This is followed by an optional precision which starts with the period
99 character (.), followed by an optional decimal integer.
100 If no integer is specified after the period character,
101 a precision of zero is used.
102 Finally, the format string should have one of the conversion specifiers
113 The conversion specifier is applied based on the floating-point type
114 indicated by the function suffix.
117 the format string does not have a length modifier character.
120 for a detailed description of these conversion specifiers.
122 The implementation conforms to the C99 standard on conversion of NaN and
128 is a NaN, +NaN, or \-NaN, and
134 is the conversion specifier, the conversion is to "nan", "nan", or "\-nan",
142 is the conversion specifier, the conversion is to "NAN" or "\-NAN".
146 is infinity, it is converted to [\-]inf or [\-]INF.
151 string results in undefined behavior.
158 functions return the number of characters that would have been written in
163 not counting the terminating null byte.
164 Thus, a return value of
166 or greater means that the output was truncated.
173 functions are available in glibc since version 2.25.
175 For an explanation of the terms used in this section, see
178 .B POSIX Safety Concepts
179 section in GNU C Library manual.
187 Interface Attribute Value
192 T} Thread safety MT-Safe locale
193 \^ Async-signal safety AS-Unsafe heap
194 \^ Async-cancel safety AC-Unsafe mem
199 Note: these attributes are preliminary.
201 C99, ISO/IEC TS 18661-1.
208 functions take account of the
210 category of the current locale.
212 To convert the value 12.1 as a float type to a string using decimal
213 notation, resulting in "12.100000":
217 #define __STDC_WANT_IEC_60559_BFP_EXT__
221 strfromf(s, ssize, "%f", 12.1);
225 To convert the value 12.3456 as a float type to a string using
226 decimal notation with two digits of precision, resulting in "12.35":
230 #define __STDC_WANT_IEC_60559_BFP_EXT__
234 strfromf(s, ssize, "%.2f", 12.3456);
238 To convert the value 12.345e19 as a double type to a string using
239 scientific notation with zero digits of precision, resulting in "1E+20":
243 #define __STDC_WANT_IEC_60559_BFP_EXT__
247 strfromd(s, ssize, "%.E", 12.345e19);