1 .\" Copyright (c) 2016, IBM Corporation.
2 .\" Written by Wainer dos Santos Moschetta <wainersm@linux.vnet.ibm.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
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.
12 .TH STRFROMD 3 2021-03-22 "GNU" "Linux Programmer's Manual"
14 strfromd, strfromf, strfroml \- convert a floating-point value into
18 .RI ( libc ", " \-lc )
21 .B #include <stdlib.h>
23 .BI "int strfromd(char *restrict " str ", size_t " n ,
24 .BI " const char *restrict " format ", double " fp ");"
25 .BI "int strfromf(char *restrict " str ", size_t " n ,
26 .BI " const char *restrict " format ", float "fp ");"
27 .BI "int strfroml(char *restrict " str ", size_t " n ,
28 .BI " const char *restrict " format ", long double " fp ");"
32 Feature Test Macro Requirements for glibc (see
33 .BR feature_test_macros (7)):
40 __STDC_WANT_IEC_60559_BFP_EXT__
43 These functions convert a floating-point value,
45 into a string of characters,
52 characters are stored into
55 The terminating null byte ('\e0') is written if and only if
57 is sufficiently large, otherwise the written string is truncated at
66 functions are equivalent to
70 snprintf(str, n, format, fp);
77 .SS Format of the format string
80 string must start with the character \(aq%\(aq.
81 This is followed by an optional precision which starts with the period
82 character (.), followed by an optional decimal integer.
83 If no integer is specified after the period character,
84 a precision of zero is used.
85 Finally, the format string should have one of the conversion specifiers
96 The conversion specifier is applied based on the floating-point type
97 indicated by the function suffix.
100 the format string does not have a length modifier character.
103 for a detailed description of these conversion specifiers.
105 The implementation conforms to the C99 standard on conversion of NaN and
111 is a NaN, +NaN, or \-NaN, and
117 is the conversion specifier, the conversion is to "nan", "nan", or "\-nan",
125 is the conversion specifier, the conversion is to "NAN" or "\-NAN".
129 is infinity, it is converted to [\-]inf or [\-]INF.
134 string results in undefined behavior.
141 functions return the number of characters that would have been written in
146 not counting the terminating null byte.
147 Thus, a return value of
149 or greater means that the output was truncated.
156 functions are available in glibc since version 2.25.
158 For an explanation of the terms used in this section, see
161 .B POSIX Safety Concepts
162 section in GNU C Library manual.
170 Interface Attribute Value
175 T} Thread safety MT-Safe locale
176 \^ Async-signal safety AS-Unsafe heap
177 \^ Async-cancel safety AC-Unsafe mem
182 Note: these attributes are preliminary.
184 C99, ISO/IEC TS 18661-1.
191 functions take account of the
193 category of the current locale.
195 To convert the value 12.1 as a float type to a string using decimal
196 notation, resulting in "12.100000":
200 #define __STDC_WANT_IEC_60559_BFP_EXT__
204 strfromf(s, ssize, "%f", 12.1);
208 To convert the value 12.3456 as a float type to a string using
209 decimal notation with two digits of precision, resulting in "12.35":
213 #define __STDC_WANT_IEC_60559_BFP_EXT__
217 strfromf(s, ssize, "%.2f", 12.3456);
221 To convert the value 12.345e19 as a double type to a string using
222 scientific notation with zero digits of precision, resulting in "1E+20":
226 #define __STDC_WANT_IEC_60559_BFP_EXT__
230 strfromd(s, ssize, "%.E", 12.345e19);